Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(vanilla/types): replace hardcoded types with StoreApi type #1459

Merged
merged 1 commit into from Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vanilla.ts
Expand Up @@ -60,7 +60,7 @@ const createStoreImpl: CreateStoreImpl = (createState) => {
let state: TState
const listeners: Set<Listener> = new Set()

const setState: SetStateInternal<TState> = (partial, replace) => {
const setState: StoreApi<TState>['setState'] = (partial, replace) => {
// TODO: Remove type assertion once https://github.com/microsoft/TypeScript/issues/37663 is resolved
// https://github.com/microsoft/TypeScript/issues/37663#issuecomment-759728342
const nextState =
Expand All @@ -77,15 +77,15 @@ const createStoreImpl: CreateStoreImpl = (createState) => {
}
}

const getState: () => TState = () => state
const getState: StoreApi<TState>['getState'] = () => state

const subscribe: (listener: Listener) => () => void = (listener) => {
const subscribe: StoreApi<TState>['subscribe'] = (listener) => {
listeners.add(listener)
// Unsubscribe
return () => listeners.delete(listener)
}

const destroy: () => void = () => listeners.clear()
const destroy: StoreApi<TState>['destroy'] = () => listeners.clear()
const api = { setState, getState, subscribe, destroy }
state = createState(setState, getState, api)
return api as any
Expand Down