https://github.com/afeiship/next-active-state
Mini state mananger based on proxy.
https://github.com/afeiship/next-active-state
active next proxy state
Last synced: 3 days ago
JSON representation
Mini state mananger based on proxy.
- Host: GitHub
- URL: https://github.com/afeiship/next-active-state
- Owner: afeiship
- License: mit
- Created: 2017-05-09T14:49:31.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T01:26:22.000Z (about 3 years ago)
- Last Synced: 2025-02-07T12:31:16.224Z (about 1 year ago)
- Topics: active, next, proxy, state
- Language: JavaScript
- Homepage:
- Size: 65.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# next-active-state
> Mini state mananger based on proxy.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]
## installation
```bash
npm install -S @jswork/next-active-state
```
## apis
| api | params | description |
| ------- | ------ | ------------------------------------ |
| 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
```js
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();
```
```js
// 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](https://github.com/afeiship/next-active-state/blob/master/LICENSE.txt).
[version-image]: https://img.shields.io/npm/v/@jswork/next-active-state
[version-url]: https://npmjs.org/package/@jswork/next-active-state
[license-image]: https://img.shields.io/npm/l/@jswork/next-active-state
[license-url]: https://github.com/afeiship/next-active-state/blob/master/LICENSE.txt
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-active-state
[size-url]: https://github.com/afeiship/next-active-state/blob/master/dist/next-active-state.min.js
[download-image]: https://img.shields.io/npm/dm/@jswork/next-active-state
[download-url]: https://www.npmjs.com/package/@jswork/next-active-state