English · 简体中文
npm install shared-store-object -S
# or
yarn add shared-store-object -S
import sso from 'shared-store-object';
// create
const like = sso(
// property
{ count: 0 },
// computed property [readonly]
{
age() {
return like.count * 2;
},
}
);
// use
console.log(like.count); // 0
console.log(like.age); // 0
// modify
like.count++;
console.log(like.count); // 1
console.log(like.age); // 1
// modify using a functional approach.
like('count', (prev) => prev + 1);
console.log(like.count); // 2
console.log(like.age); // 4
// revoke
like();
//
import sso from 'shared-store-object';
// when using React < 18, use batch updates to configure globally.
sso.config({ next: ReactDOM.unstable_batchedUpdates });
import sso from 'shared-store-object';
const app = sso({
count: 0,
});
app((): Partial<SSOConfig> => {
return {
next(iteration, key, data) {
console.log('app', key, data);
iteration();
},
};
});