sign

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

sign

Sign #
Basic state management base for dart. Sign inspired QT framework signal-slot architecture.
This package is supported all platforms include dart sdk.
For Flutter: sign_flutter
Flutter package has some Widgets for signal and some extensions to generate signal from ChangeNotifier
and ValueNotifier.
1) What is Signal? #
Signal is simply a class that triggers a function when its value changes (or on request).
In this regard, Signal is very similar to Flutter's ChangeNotifier or ValueNotifier, GetX's observable, or
Provider's StateNotifier.
Signal has some minor differences. First it is independent of Flutter. And its so simple, it lacks the long lines of
code that control so many cases.
It also works with Slot instead of callbacks.
Basically there are only 3 things:
1. Signal : Signal has a value. This is the class that triggers the function when value changes or sign() called.
2. Slot : Slot can be added to desired Signals. Signal triggers are handled with Slot.onValue when added to a Signal.
3. MultiSignal : MultiSignal is both a Slot and a Signal. It collects triggers from different Signals as one Slot and works like a single Signal.

How To Use? #

Define a Signal implementation or create a Signal from any variable.


/// Create a Signal from a variable
final Signal<int> signal = 0.signal;

void f() {
signal.value++;
// OR
signal.sign();
}

/// Define signal implementation
class MySignal extends Signal<int> {
MySignal() : super(0);

void changeSomething() {
// Change signal value to trigger signal
value = newValue;

// Or use sign() to trigger signal
sign();
}
}
copied to clipboard

Define a Slot implementation.


class MySlot extends Slot<int> {
MySlot() : super();

@override
void onValue(int value) {
// Do something
}
}
copied to clipboard
In Flutter you can create states that are themselves a slot. You can use aSignal.builder() or SlotWidget for this.

Add a Slot to a Signal.

void f() {
// Add a Slot to a Signal
signal.addSlot(MySlot());
}
copied to clipboard
Special Signal Classes #
If you want to trigger changes on List and Map, you don't need to use an expression like value = newList.
Statements like these reduce performance significantly.
You can use SignalList and SignalMap instead.
SignalList and SignalMap trigger a signal in any case that changes the collection content.

final signalList = <int>[].signalList;
final signalMap = <String,String>{}.signalMap;
void f() {
signalList.add(1); // triggered

signalList.remove(1); // triggered

signalList.clear(); // triggered

signalList[0] = 10; // triggered

signalMap['a'] = 'b'; // triggered

signalMap.remove('a'); // triggered

}
copied to clipboard
To create a SignalList, use SignalList constructors or create with list.signalList.
To create a SignalMap, use SignalMap constructors or create with map.signalMap.
GlobalSignal / GlobalSlot #
GlobalSlots are triggered by changes in same generic type GlobalSignal without the
need to add to GlobalSignals.
GlobalSignal must be created only once or disposed before creating a new instance.
void main(){
var globalCounter = GlobalCounter();

GlobalCountSlot('a');
GlobalCountSlot('b');
GlobalCountSlot('c');
GlobalCountSlot('d');
GlobalCountSlot('e');


globalCounter.value++;
// GlobalCountSlot 'a', 'b', 'c', 'd', 'e' triggered
}

class GlobalCounter extends GlobalSignal<int> {
GlobalCounter() : super(0);

void increment() {
value++;
}

void decrement() {
value--;
}
}

class GlobalCountSlot extends GlobalSlot<int, GlobalCounter> {
GlobalCountSlot(this.name);

String name;

@override
void onValue(int value) {
print('GlobalCountSlot : $name : $value');
}
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator