Skip to content

Commit

Permalink
Tweak types and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Jul 26, 2022
1 parent 0d13a78 commit 75d0a40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-points-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"statery": minor
---

Simplify types.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import { useLayoutEffect, useRef, useState } from "react"
*/

/**
* The state objects managed by Statery stores are any JavaScript objects that
* can be indexed using strings and/or numbers.
* The state objects managed by Statery stores are any string-indexed JavaScript objects.
*/
export type State = Record<string | number, any>
export type State = Record<string, any>

/**
* Statery stores wrap around a State object and provide a few functions to update them
Expand Down Expand Up @@ -84,7 +83,7 @@ export type Listener<T extends State> = (updates: Readonly<Partial<T>>, state: R
/**
* Creates a Statery store and populates it with an initial state.
*
* @param state The state object that will be wrapped by the store.
* @param initialState The state object that will be wrapped by the store.
*/
export const makeStore = <T extends State>(initialState: T): Store<T> => {
let state = initialState
Expand All @@ -105,6 +104,7 @@ export const makeStore = <T extends State>(initialState: T): Store<T> => {
/* If the argument is a function, run it */
const updates = getActualChanges(incoming instanceof Function ? incoming(state) : incoming)

/* Has anything changed? */
if (Object.keys(updates).length > 0) {
/* Keep a reference to the previous state, we're going to need it in a second */
const previousState = state
Expand Down

0 comments on commit 75d0a40

Please sign in to comment.