shared-store-object
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Shared Store Object

version install size download sso

English · 简体中文

Install

npm install shared-store-object -S
# or
yarn add shared-store-object -S

Use

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();
//

Configuration

Global configuration

import sso from 'shared-store-object';

// when using React < 18, use batch updates to configure globally.
sso.config({ next: ReactDOM.unstable_batchedUpdates });

Separate configuration

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();
    },
  };
});

Readme

Keywords

none

Package Sidebar

Install

npm i shared-store-object

Weekly Downloads

22

Version

1.1.1

License

MIT

Unpacked Size

11.2 kB

Total Files

5

Last publish

Collaborators

  • moneko