All Projects → Jaguar-dart → observable_ish

Jaguar-dart / observable_ish

Licence: BSD-3-Clause License
Observable state and events for browser and Flutter.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to observable ish

Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+796.15%)
Mutual labels:  map, set, list
Gods
GoDS (Go Data Structures). Containers (Sets, Lists, Stacks, Maps, Trees), Sets (HashSet, TreeSet, LinkedHashSet), Lists (ArrayList, SinglyLinkedList, DoublyLinkedList), Stacks (LinkedListStack, ArrayStack), Maps (HashMap, TreeMap, HashBidiMap, TreeBidiMap, LinkedHashMap), Trees (RedBlackTree, AVLTree, BTree, BinaryHeap), Comparators, Iterators, …
Stars: ✭ 10,883 (+41757.69%)
Mutual labels:  map, set, list
NonEmptyCollections
A type-safe implementation for collections that cannot be empty. Life is too short for emptiness-checks!
Stars: ✭ 45 (+73.08%)
Mutual labels:  map, set, list
Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
Stars: ✭ 125 (+380.77%)
Mutual labels:  map, set, list
Redisson
Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Stars: ✭ 17,972 (+69023.08%)
Mutual labels:  map, set, list
Hprose Delphi
Hprose is a cross-language RPC. This project is Hprose 2.0 for Delphi and FreePascal
Stars: ✭ 100 (+284.62%)
Mutual labels:  map, list
Redux Data Structures
Reducer factory functions for common data structures: counters, maps, lists (queues, stacks), sets, etc.
Stars: ✭ 157 (+503.85%)
Mutual labels:  map, set
Hamt
Immutable and Memory-Efficient Maps and Sets in Go
Stars: ✭ 213 (+719.23%)
Mutual labels:  map, set
dead-simple
💀💡 Dead simple PubSub and EventEmitter in JavaScript
Stars: ✭ 21 (-19.23%)
Mutual labels:  events, emitter
Collection
A PHP library for representing and manipulating collections.
Stars: ✭ 488 (+1776.92%)
Mutual labels:  map, set
EventEmitter
Simple EventEmitter with multiple listeners
Stars: ✭ 19 (-26.92%)
Mutual labels:  events, observable
realar
5 kB Advanced state manager for React
Stars: ✭ 41 (+57.69%)
Mutual labels:  reactive, observable
game-map-editor
game-map-editor
Stars: ✭ 17 (-34.62%)
Mutual labels:  map, events
Buckets Js
A complete, fully tested and documented data structure library written in pure JavaScript.
Stars: ✭ 1,128 (+4238.46%)
Mutual labels:  map, set
muon-java
Muon Core for the JVM. APIs and Microservices taken to the next level
Stars: ✭ 18 (-30.77%)
Mutual labels:  events, reactive
bound
Data-binding made easy
Stars: ✭ 21 (-19.23%)
Mutual labels:  reactive, binding
rxrest
Reactive rest library
Stars: ✭ 33 (+26.92%)
Mutual labels:  reactive, observable
WpfExtensions
Some syntactic sugar for Wpf development.
Stars: ✭ 128 (+392.31%)
Mutual labels:  reactive, binding
Php Enum
Simple and fast implementation of enumerations with native PHP
Stars: ✭ 446 (+1615.38%)
Mutual labels:  map, set
php-sorted-collections
Sorted Collections for PHP
Stars: ✭ 22 (-15.38%)
Mutual labels:  map, set

observable_ish

Write elegant reactive cross-platform client side application using observable states and event emitters.

Provides:

  1. Reactive Values
  2. Reactive Lists
  3. Reactive Sets
  4. Reactive Maps
  5. Event emitter

Philosophy

Observable-ish provides a light-weight non-intrusive reactive framework to build cross-platform UI. It uses Dart's asynchronous Streams to emit and listen to changes.

Various observable types like RxValue, RxList, RxSet and RxMap can be used to update UI automatically on changes. Events can be passed up the widget tree using event Emitter.

Reactive values

RxValue can be used to encapsulate a simple observable value.

Getting and setting value

RxValue exposes field value to get set current value.

main() {
  final rxInts = RxValue<int>(initial: 5);
  int got = rxInts.value; // Gets current value
  rxInts.value = 10;      // Sets current value
}

When a value that is different from the existing value is set, the change is notified through various ways explained in the section.

Listening to changes

It provides few flexible ways to listen to changes:

  1. onChange: Record of changes
  2. values: Stream of new values
  3. listen: Callback function with new value
main() {
  final rxInts = RxValue<int>(initial: 5);
  print(rxInts.value);  // => 5
  rxInts.values.listen((int v) => print(v));  // => 5, 20, 25
  rxInts.value = 20;
  rxInts.value = 25;
}

Binding to a value

Binding an RxValue to a Stream (using method bindStream) or another RxValue (using method bind) changes its value when the source Stream emits or RxValue changes. This is very useful in scenarios where one would like to change a model's value or widget's property when control changes. For example, change a text field's value when a checkbox is toggled.

  textBox.value.bindStream(checkBox.checked.map((bool v) => v?'Female': 'Male'));

Full examples

main() {
  final rxInts = RxValue<int>(initial: 5);
  print(rxInts.value);  // => 5
  rxInts.value = 10;
  rxInts.value = 15;
  rxInts.values.listen((int v) => print(v));  // => 15, 20, 25
  rxInts.value = 20;
  rxInts.value = 25;
}

Composite reactive objects

Observable-ish is designed to be non-intrusive. The philosophy is to separate the model and its reactive cousin into different classes.

class RxUser {
  final name = RxValue<String>();
  final age = RxValue<int>();
}

class User {
  final rx = RxUser();

  User({String name, int age}) {
    this.name = name;
    this.age = age;
  }

  String get name => rx.name.value;
  set name(String value) => rx.name.value = value;

  int get age => rx.age.value;
  set age(int value) => rx.age.value = value;
}

main() {
  final user = User(name: 'Messi', age: 30);
  user.age = 31;
  print(user.age);  // => 31
  print('---------');
  user.age = 32;
  user.rx.age.listen((int v) => print(v));  // => 20, 25
  user.age = 33;
  user.age = 34;
  user.age = 35;
}

Event emitter

Emitters provide a simple interface to emit and listen to events. It is designed to inter-operate with RxValue to provide maximum productivity.

Listening to a event

  1. on: Execute callback on event
  2. listen: Similar to Stream
  3. asStream: Obtain event as Stream

Piping events

pipeTo pipes events to another Emitter.

pipeToValue pipes events to the given RxValue. This could be very helpful in binding events to observable values.

Emitting events

emit, emitOne, emitAll, emitStream and emitRxValue provides various ways to emit events using the Emitter

Reactive Lists

RxList notifies changes (addition, removal, clear, setting) of its elements.

Updating RxList

RxList implements Dart's List.

Besides List's methods, RxList provides convenient methods like addIf and addAllIf to add elements based on a condition. This is very useful in writing UI in Dart DSL (as in Flutter and Nuts).

main() {
  final rxInts = RxList<int>();
  rxInts.onChange.listen((c) => print(c.element)); // => 5
  rxInts.addIf(5 < 10, 5);
  rxInts.addIf(5 > 9, 9);
}

Use assign and assignAll methods to replace existing contents of the list with new content.

Listening for changes

onChange exposes a Stream of record of change of the List.

Reactive Sets

RxSet notifies changes (addition and removal) of its elements.

Updating RxSet

RxSet implements Dart's Set.

Besides Set's methods, RxSet provides convenient methods like addIf and addAllIf to add elements based on a condition. This is very useful in writing UI in Dart DSL (as in Flutter and Nuts).

main() {
  final rxInts = RxSet<int>();
  rxInts.onChange.listen((c) => print(c.element)); // => 5
  rxInts.addIf(5 < 10, 5);
  rxInts.addIf(5 > 9, 9);
}

Listening for changes

onChange exposes a Stream of record of change of the Set.

Binding

bindBool and bindBoolValue allows removing or adding the given element based on the Stream of bools or RxValue of bools.

bindOneByIndexStream and bindOneByIndex allows removing all but the one element from a given Iterable of elements based on index Stream or RxValue.

Reactive Maps

RxMap notifies changes (addition, removal, clear, setting) of its elements.

Updating RxMap

RxMap implements Dart's Map.

Besides Map's methods, RxMap provides convenient methods like addIf and addAllIf to add elements based on a condition. This is very useful in writing UI in Dart DSL (as in Flutter and Nuts).

Listening for changes

onChange exposes a Stream of record of change of the Map.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].