1.0.14 • Published 1 year ago

@jswork/next-active-state v1.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

next-active-state

Mini state mananger based on proxy.

version license size download

installation

npm install -S @jswork/next-active-state

apis

apiparamsdescription
get-Unwrap proxy data to pure js object.
on-Watch changed and return destroy fn.
one-Watch changed and return destroy fn.
reset-Watch changed and return destroy fn.
touched-Get state has touched.
#use-Use object with listener.
#toJS-Transform to pure js object.

usage

import NxActiveState from '@jswork/next-active-state';

const data = { key: 1, value: 2 };
const instance = new NxActiveState(data);
const state = instance.state;

const res = instance.on('change', (arg) => {
  console.log(arg);
});

// create
state.newKey = 'I am new.';

// update
state.key = 122;

// delete
delete state.value;

// destroy resource
res.destroy();
// simple use
const data = { key: 1, value: 2 };
const state = NxActiveState.use(data, (arg) => {
  console.log(arg);
});

// create
state.newKey = 'I am new.';

// update
state.key = 122;

// delete
delete state.value;

// no need to destroy resource

license

Code released under the MIT license.