-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
32 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class _Okito {} | ||
|
||
// To implement in future | ||
// ignore: non_constant_identifier_names | ||
final _Okito Okito = _Okito(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
import '../bin/controller.dart'; | ||
import '../types/callback_types.dart'; | ||
import 'listener.dart'; | ||
import 'watcher.dart'; | ||
|
||
class _ControllerCommunication<Okito> { | ||
final _listeners = <Listener>{}; | ||
final _watchers = <Watcher>{}; | ||
|
||
/// [notify] method is the method called when you use 'update' or 'setState'. | ||
void notify<T extends Okito>(T type) { | ||
for (var listener in _listeners) { | ||
if (listener.event == type) { | ||
listener.callback(); | ||
for (var watcher in _watchers) { | ||
if (watcher.event == type) { | ||
watcher.callback(); | ||
} | ||
} | ||
} | ||
|
||
/// With [watch] method, state watches changes that are coming from notify. | ||
Function watch<T extends Okito>(T type, VoidCallback<Object> callback) { | ||
var listener = Listener(type, callback); | ||
_listeners.add(listener); | ||
var watcher = Watcher(type, callback); | ||
_watchers.add(watcher); | ||
|
||
return () => _listeners.remove(listener); | ||
return () => _watchers.remove(watcher); | ||
} | ||
} | ||
|
||
final _ControllerCommunication controllerXstate = | ||
/// ### For Developers | ||
/// | ||
/// The [controllerXview] is a bridge between controller | ||
/// and view(stateful widget). | ||
/// | ||
/// In the okito, we don't use Dependency Injection, instead we use | ||
/// set with watchers which is triggered whenever a controller | ||
/// notifies the state to update/re-build. | ||
final _ControllerCommunication controllerXview = | ||
_ControllerCommunication<OkitoController>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import '../types/callback_types.dart'; | ||
|
||
class Listener<T> { | ||
class Watcher<T> { | ||
final T event; | ||
final VoidCallback callback; | ||
|
||
const Listener(this.event, this.callback); | ||
const Watcher(this.event, this.callback); | ||
} |