1.0.2 • Published 5 years ago

@muzikanto/observable-global v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Observable

npm version downloads dependencies Status size Code style

Introduction

  • create global store
  • async append store part
  • listen store changes
  • listen store object part change
  • create event and subscribe store to event
  • and more..

Installation

npm i @muzikanto/observable @muzikanto/observable-global
# or
yarn add @muzikanto/observable @muzikanto/observable-global

Example

Example use

example create store

export interface GlobalState {
   userName: string | null;
}

const makeStore = (initialState: Partial<GlobalState>) => {
   return combineAsync({
      userName: createStore(initialState.userName || ''),
   });
};

const store = getOrCreateStore(makeStore, { userName: 'Maxim' });

example async inject

// ...
const store = getOrCreateStore(makeStore, { userName: 'Maxim' });

const asyncStore = createStore(1);

store.injectStore('asyncStore', asyncStore);

example connect

function Component() {
   const userName = useGlobal((globalState) => globalState.userName);

   return <span>{userName}</span>;
}

License

MIT

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago