5.0.1 • Published 5 years ago

justore v5.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Justore

Build Status via Travis CI NPM version js-standard-style

We don't need flux , just the store!

Installation

npm install justore --save

Basic Usage

var justore = require("justore");
var initData = {};
var store = new justore(initData,'Store Name');


//Write or change data to store, return a Promise
store.write('todos',['drink','cook']);

//Subscribe to change
let subscription = store.sub('todos.0',function(newVal,prevVal){
  store.read('todos') === newVal //true, 'drink'
});
//Remember to clean up
subscription.unsubscribe();

Advanced usage

  • store.batchWrite([keyPaths], manipulateFunction); Batch write multiple data to the store, only emit if it's listed on the keyPaths
    store.batchWrite(['vtext', 'enable'], draft => {
      draft.vtext.i = 10
      draft.enable = true
      draft.pos = 12 // works, but no event emit
    });
  • store.write(keyPath, data [,options])

    Write data to the store, return store

    store.write('todos',['drink','cook'],{
      //Boolean. If true, change the store without trigger any events
      mute:false
    });
  • store.sub(keyPath[,onNext][,immediate])

    Subscribe to the store, if onNext is defined, return an Rx Subscription, else return an Rx stream

    store.sub('todos.1',function (newVal, oldVal) {
  	  //do tings
    });
  • store.read(keyPath)

    Get value for attribute by passing the key.

    store.read("todos.0") //--> 'drink'
  • store.delete(keyPath)

    Useful when you want to delete a root key and it's data

    store.delete("todos")
    store.report()  //--> {}
  • store.report()

    return the full store data. You cannot manipulate it

  • store.debugOn

    if a key in this array, will toggle JS breakpoints when writing that key

React Mixin helper

  • store.createReactMixin(key)

    Return a mixin. Will call onStoreChange method on a React component when store change.

Auto unsubscibe

If the subscribed data has been deleted (not set to undefined), the subscription will unsubscribe automatically

Browser support

IE11 or higher
5.0.1

5 years ago

5.0.0

5 years ago

4.0.0

5 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.10

7 years ago

1.3.9

7 years ago

1.3.8

7 years ago

1.3.6

8 years ago

1.3.5

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago