minimalist-store

1.0.0 • Public • Published

a minimalist store using as maximum as possible of native object features + Proxy

Usage Example

import createModel from 'minimalist-store';

const store = {
  name: 'Diel',
  age: 10,
  get doubleAge() {
    return this.age * 2;
  }
};

const model = createModel(store);

// randomly generating a new `age` value each 400ms, just to test
setInterval(() => {
  model.set = { age: Math.random() };
}, 400);

// add a subscribe by fields that you wanna do something when updated
// subscribe can be used multiple times, 
// passing a list of fields to watch
model.subscribe(['age'], () => {
  console.log('new change >>>', model.doubleAge);
});

Readme

Keywords

none

Package Sidebar

Install

npm i minimalist-store

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.2 kB

Total Files

5

Last publish

Collaborators

  • dielduarte