pullstate

Simple state stores using immer and React hooks - re-use parts of your state by pulling it anywhere you like!

MIT License

Downloads
20.3K
Stars
1.1K
Committers
9
pullstate - 1.21.0 - React 17, cache break and batch() Latest Release

Published by lostpebble over 3 years ago

Added in a batch() function which allows you to run multiple Store.update() inside of it, and have all the updates be batched at the same time to your App. Updates in batch() must be synchronous (can't be an async function). This allows defining cross-store updates in a more performant way, when these changes are made outside of the React event structures (regular button clicks etc.- these are batched by React by default).

Async Actions now also accept an extra option when being consumed:

const getImagesAction = GetImages.use({ tag: "green" }, { cacheBreak: true });

cacheBreak can be a boolean or a function which returns a boolean value (the function signature is the same as the regular cacheBreakHook that you can set when creating Async Actions).

This allows you to more finely control the cache breaking per a component- the next time a component is mounted, it will check this value and decide if we need to run the action anew.

This can also go hand-in-hand with another option: holdPrevious: true - which will hold the previously result of the Async Action (if its available) while the action runs again on the cache break.


Pullstate now also defines that it supports the peer dependency of react for versions ^17.0.0 as well- this prevents NPM errors in the newer version, which is more strict about peer dependencies.

pullstate - 1.20.1 React Native Debugger fix

Published by lostpebble almost 4 years ago

Using registerInDevtools() should now work with the Redux React Native debugger implementation. Thanks to @wnz99 for championing this change.

pullstate - 1.20.0 - Async Error Payloads

Published by lostpebble almost 4 years ago

Minor Release. Thanks to @ultd for bringing up the suggestion and working on these changes.

  • Allow the passing of an errorPayload to the end result of an Async Action.
// response from inside an async action
return errorResult(["NOT_FOUND"], "User was not found", errorPayload)

This allows you to pass an additional object which you define, in order to communicate more information / data about what went wrong.

If an async action has finished resolving, and is in an error state (isFailure represents this when making use of AsyncAction.use()), then the error payload will be defined (if you have passed something in for it):

const getUserAction = GetUserAsyncAction.use({ userId: "asd" });

if (getUserAction.isFailure) {
  getUserAction.errorPayload // <- Would be defined if you are making use of it
}
pullstate - 1.19.0 - Async fixes and useDefer

Published by lostpebble about 4 years ago

(Unfortunately I skipped 1.18.0 by mistake...)

Some internal fixes for Async Actiosn and a new deferred way to run and watch action state

AsyncAction.useDefer()

You can now now use Async Actions with a method called useDefer(). This method allows you to defer the execution of an action in a later trigger further down inside your component or its children. What's really nice about this is that you don't need to know the arguments beforehand, as you do with the regular action use. This is great for listening to tasks and showing state in a parent component, which is triggered further down in a child component (such as button click on "Update User" or some kind of form submit).

const deferredAction = UpdateUser.useDefer();

// ... somewhere later or in another component

<button onClick={() => defferedAction.execute(newUserData)}>Update User</button>

This simplifies a lot of scenarios with Async Actions.

pullstate - 1.17.0 - Local Component Stores

Published by lostpebble about 4 years ago

Added useLocalStore() function for allowing the use of pullstate stores to replace regular React.useState() in some scenarios, as local state within your components (non-global state stores).

As extras, you can also call MyStore.useLocalCopyInitial() or MyStore.useLocalCopySnapshot() on any of your stores to create a local component-lifetime copy of those stores- either set to whatever your stores state was initially or a snapshot of what it is at this moment, respectively.

pullstate - Added UMD export

Published by lostpebble about 4 years ago

Can be accessed from https://unpkg.com/[email protected]/dist/pullstate.umd.js in your plain browser HTML projects.

pullstate - 1.16.0

Published by lostpebble over 4 years ago

Fix to caching of running actions, which disallows double running of actions when used in both a useBeckon() and run() situation at the same time (while respectCache is true).

pullstate - 1.15.3 - Draft<S> type update

Published by lostpebble over 4 years ago

Fixes #48

Adds Draft<S> wrapper around the draft state in an update function, allowing updates on readonly types inside a store.

pullstate - 1.15.2

Published by lostpebble over 4 years ago

Added the ability to "namespace" the devtools integration. This prevents clashes when working on multiple apps at the same time. Passable as an option in the second argument to registerInDevtools()

pullstate - Redux Devtools Integration

Published by lostpebble over 4 years ago

Thanks to @lukasmoellerch for helping to bring about these changes.

Added integration with Redux Devtools. Make use of registerInDevtools(Stores) to use it. Argument is an object of { [storeName: string]: Store } - which will register your stores instanced according to the name provided.

pullstate -

Published by lostpebble over 4 years ago

Updated dependencies. Minor for fast-deep-equal.

Pullstate now requires immer@^7.0.0