Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jonatas
2020-12-23 17:57:41 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a5a163241a62846ba5913023f51b3b409f4922d6
a5a16324
1 parent
2a9c2af9
added debounce to update
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
lib/get_state_manager/src/simple/list_notifier.dart
lib/get_utils/src/queue/get_queue.dart
lib/get_state_manager/src/simple/list_notifier.dart
View file @
a5a1632
import
'dart:async'
;
import
'dart:collection'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -10,6 +11,12 @@ typedef Disposer = void Function();
typedef
GetStateUpdate
=
void
Function
();
class
ListNotifier
implements
Listenable
{
int
_version
=
0
;
int
_microtask
=
0
;
int
get
notifierVersion
=>
_version
;
int
get
notifierMicrotask
=>
_microtask
;
List
<
GetStateUpdate
>
_updaters
=
<
GetStateUpdate
>[];
HashMap
<
String
,
List
<
GetStateUpdate
>>
_updatersGroupIds
=
...
...
@@ -18,21 +25,50 @@ class ListNotifier implements Listenable {
@protected
void
refresh
()
{
assert
(
_debugAssertNotDisposed
());
/// This debounce the call to update.
/// It prevent errors and duplicates builds
if
(
_microtask
==
_version
)
{
_microtask
++;
scheduleMicrotask
(()
{
_version
++;
_microtask
=
_version
;
_notifyUpdate
();
});
}
}
void
_notifyUpdate
()
{
for
(
var
element
in
_updaters
)
{
element
();
}
}
@protected
void
refreshGroup
(
String
id
)
{
assert
(
_debugAssertNotDisposed
());
void
_notifyIdUpdate
(
String
id
)
{
if
(
_updatersGroupIds
.
containsKey
(
id
))
{
for
(
var
item
in
_updatersGroupIds
[
id
])
{
final
listGroup
=
_updatersGroupIds
[
id
];
for
(
var
item
in
listGroup
)
{
item
();
}
}
}
@protected
void
refreshGroup
(
String
id
)
{
assert
(
_debugAssertNotDisposed
());
/// This debounce the call to update.
/// It prevent errors and duplicates builds
if
(
_microtask
==
_version
)
{
_microtask
++;
scheduleMicrotask
(()
{
_version
++;
_microtask
=
_version
;
_notifyIdUpdate
(
id
);
});
}
}
bool
_debugAssertNotDisposed
()
{
assert
(()
{
if
(
_updaters
==
null
)
{
...
...
lib/get_utils/src/queue/get_queue.dart
View file @
a5a1632
import
'dart:async'
;
class
GetMicrotask
{
int
_version
=
0
;
int
_microtask
=
0
;
int
get
version
=>
_version
;
int
get
microtask
=>
_microtask
;
void
exec
(
Function
callback
)
{
if
(
_microtask
==
_version
)
{
_microtask
++;
scheduleMicrotask
(()
{
_version
++;
_microtask
=
_version
;
callback
();
});
}
}
}
class
GetQueue
{
final
List
<
_Item
>
_queue
=
[];
bool
_active
=
false
;
...
...
Please
register
or
login
to post a comment