From 87cd0c28bb76c78671618952376d36234e438fcf Mon Sep 17 00:00:00 2001 From: Daniel Loomer Date: Sat, 24 Apr 2021 15:38:21 -0400 Subject: [PATCH] add test file for types --- .npmignore | 9 ++++++--- type-test.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 type-test.ts diff --git a/.npmignore b/.npmignore index 24c5f79..b0f5ec0 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,9 @@ -build.js .vscode -/staterino.js yarn.lock .prettierrc -.eslintrc.js \ No newline at end of file +.eslintrc.js + +/build.js +/staterino.js +/staterino.test.js +/type-test.js \ No newline at end of file diff --git a/type-test.ts b/type-test.ts new file mode 100644 index 0000000..6b6d3d3 --- /dev/null +++ b/type-test.ts @@ -0,0 +1,40 @@ +import staterino from 'staterino' + +interface State { + book: boolean + house: number + nested: { + hi: number + } +} + +const initialState: State = { + book: true, + house: 10, + nested: { + hi: 3 + } +} + +const useStore = staterino({ + state: initialState, + hooks: { useLayoutEffect: true, useReducer: true }, + merge: () => null +}) + +const val = useStore(s => s.house) + +const [blah, house, hi] = useStore(['hi', s => s.house, s => s.nested.hi]) + +useStore.subscribe( + s => s.book, + book => console.log(book) +) + +useStore.subscribe([s => s.house, s => s.nested.hi], (house, hi) => {}) +useStore.subscribe(s => {}) +useStore.subscribe([s => s.book, 'hello'], (book, h) => {}) + +useStore.set([{ book: true }, { nested: {} }, s => s, [[[{ house: 3 }]]]]) + +const s = useStore()