Skip to content

Commit

Permalink
add test file for types
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzetsu committed Apr 24, 2021
1 parent 5afd823 commit 87cd0c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
build.js
.vscode
/staterino.js
yarn.lock
.prettierrc
.eslintrc.js
.eslintrc.js

/build.js
/staterino.js
/staterino.test.js
/type-test.js
40 changes: 40 additions & 0 deletions type-test.ts
Original file line number Diff line number Diff line change
@@ -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>({
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()

0 comments on commit 87cd0c2

Please sign in to comment.