1.0.7 • Published 8 months ago

reactive-mapjs v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Reactive Map

Description

Javascript Map Extension.

Implementing Observer Design pattern through SOLID principles, providing reactivity for:

  • set.
  • clear.
  • delete.

Notifying the events and deltas, upon invoking those methods.

Disclaimer

This is NOT part of rxjs library, and it is not compatible with rxjs Observable (at this moment).

For efficiency and speed, I've decided not to enforce immutability, that is upon YOU, the consumer to never manipulate the delta, and only do reads from it.

install

npm i reactive-mapjs

Use

import {ReactiveMap} from "reactive-map"

function callback(event, delta){
    console.log(event,delta);
    //Do code...
}

const reactiveMap = new ReactiveMap();
const subscription = reactiveMap.subscribe();

reactiveMap.set("hello", "world");
//Output: set , {key: "hello", value: "world"}

reactiveMap.set("goodbye", "developer");
//Output: set , {key: "goodbye", value: "developer"}
console.log(reactiveMap.size); //Ouput 2

reactiveMap.delete("hello");
//Output: delete , {key: "goodbye", value: "developer"}
console.log(reactiveMap.size) //Ouput 1

reactiveMap.clear()
//Output: clear , Map(1) { "hello" => "world" }
console.log(reactiveMap.size) //Ouput 0

//free memory, stop event propagation
subscription.unsubscribe();

Note:

in future version, I might add WeakRef to allow the gardbadge collection to free memory that wasn't unsubscribe, and remove it from event propagation, this is yet to be decided.

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago