Skip to content

Releases: ctrlplusb/easy-peasy

v3.2.3

08 Nov 17:26
Compare
Choose a tag to compare

Patches

  • Small fix to mergeDeep persistence rehydrate strategy: 501f237

v3.2.2

08 Nov 17:16
Compare
Choose a tag to compare

Patches

  • Minor improvement to types: 16c7d13
  • Small fix on mergeDeep strategy for persistence rehydration: 38de869
  • Adds more TS test coverage: 01fd077
  • Updates deps: 5e033e2

v3.2.1

05 Nov 15:58
Compare
Choose a tag to compare

Patches

  • Fixes typescript issue with generics and actions: bd9e978

v3.2.0

01 Nov 16:40
Compare
Choose a tag to compare

Minor Changes

  • Adds store persistence APIs: #343

Patches

v3.1.2

30 Oct 12:05
Compare
Choose a tag to compare

Patches

  • Fixes actions allowing them to return new state without explicitly having to disable immer: 7f13514

v3.1.1

28 Oct 10:45
Compare
Choose a tag to compare

Patches

  • Fixes compatibility with react-redux provider.: e199314
  • Fixes debug helper, and updates it's docs: fb63aac

v3.1.0

01 Oct 23:20
Compare
Choose a tag to compare

Minor Changes

Patches

  • Fixed some lint issues: 740d1a4
  • Update testing-actions.md: 52a8561
  • πŸ“ Add comma at action listener example: 5963568
  • Update adding-typed-actions.md: c92ff7c
  • Update adding-typed-thunks.md: e0ddb22
  • Fix: added html suffix to store links within docs;: d3cc2b5
  • Reduce the number of mapped types used in state mapper: 66da041
  • Prevent state updates on unmounted components: 65a2fd8
  • Minor tweak to typescript state mapper: c4efa4f
  • Upgrades dependencies: ea8aa83
  • Adds generic model typescript case: 08ab8d9

v3.0.2

19 Aug 15:19
Compare
Choose a tag to compare

Patches

  • Updates deps: ee424b4
  • Adds warning about invalid computed property access: 6992dc9
  • Bumps deps and version: a4202a7

v3.0.1

01 Aug 10:13
Compare
Choose a tag to compare

Patches

v3.0.0

23 Jul 15:53
Compare
Choose a tag to compare

v3 is considered the realisation of the "final" Easy Peasy API - taking all the evolution and learning from v2 to produce a long term stable API that we will commit to supporting and will do our best to avoid breaking changes moving forward.

New Features

Hot reloading support

Hot reloading is supported via the store.reconfigure(model) API. See #168

New actionOn and thunkOn APIs

These are the new and only APIs by which to define action/thunk listeners with.

The v3 website has been updated with tutorials and API docs introducing these APIs.

We are really sorry about the churn around listener APIs! This API was driven by community feedback so feeling far better about it. πŸ‘

Breaking Changes

Removed deprecated APIs

Thunks can be either asynchronous and synchronous

Using async/await or returning a Promise from a thunk will maintain its previous async behaviour.

However, if you do neither of the above your thunk will be executed synchronously. Therefore you can now get eager updates to your state if all you do is dispatch actions within your thunk. This can be handy for encapsulating logic based action dispatching.

For example

addProduct: thunk((actions, payload) => {
  switch (payload.type) {
    case 'SHOES': 
		actions.addShoe(payload);
        break;
    case 'VEGETABLE':
        // ...
  }
});

Returning immutable state from actions

If you prefer to return new immutable state from your actions, rather than mutating the state, you need to set the new disableImmer flag.

import { createStore, action } from 'easy-peasy';

const model = {
  todos: [],
  addTodo: action((state, payload) => {
    // πŸ‘‡ new immutable state returned
    return [...state, payload];
  })
}

const store = createStore(model, {
  disableImmer: true // πŸ‘ˆ set the flag
})

Failing to disable immer may result in strange errors if you are using computed properties.

computed

In order to optimise the Typescript experience we have made a fairly small change to the computed API. If you wish to use state resolvers, these now need to be defined as the first argument.

Before

const basketModel = {
  productIds: [],
  products: computed(
    (productIds, products) => productIds.map(id => products[id]),
    [
      state => state.productIds,
      (state, storeState) => storeState.products.items
    ]
  )
};

After

const basketModel = {
  productIds: [],
  products: computed(
    [
      state => state.productIds,
      (state, storeState) => storeState.products.items
    ],
    (productIds, products) => productIds.map(id => products[id])
  )
};

Computed properties not using state resolvers remain unchanged.

useStoreState API update

useStoreState(previouslyuseStore) no longer needs/accepts the dependencies 2nd argument. Your state will get mapped correctly if they use external values, like props, within the mapState` function.

Typescript

We officially support >= [email protected]. Although we recommend using the latest version ([email protected] at the time of writing), in order to ensure you are up to date with the latest bug fixes.

Create React App users can just install [email protected] as a dev dependency and the CRA build system will use that version. You may get a warning printed to your console, however, we experienced no issues with this. πŸ‘

Note: using a lower version of TypeScript 3.x may still work, however, you may have issues.

Hooks

You will have noted above that the useStoreState, useStoreActions, and useStoreDispatch are no longer attached to the store instance. You need to use the createTypedHooks helper instead.

import { createTypedHooks } from 'easy-peasy';
import { StoreModel } from './model';

const { useStoreActions, useStoreState, useStoreDispatch } = createTypedHooks<StoreModel>();

export default {
  useStoreActions,
  useStoreState,
  useStoreDispatch
}

Computed

The Computed type no longer requires you to define the types for state resolvers. These will automatically be inferred.

Before

interface BasketModel {
  productIds: string[];
  products: Computed<
    BasketModel, 
    Product[], 
    ResolvedState2<string[], Product[]>, 
    StoreModel
   >
}

After

interface BasketModel {
  productIds: string[];
  products: Computed<
    BasketModel, 
    Product[],
    StoreModel
   >
}

Commits

  • Update overview.md: f5fbe87
  • Removes deprecated code: ba955a5
  • Removes unused assets: 0a06ee8
  • Cleans up and organises the typescript definitions: 78dc4d4
  • Adds depth limit to State and Actions typescript definitions: 55375dc
  • Fixes index signatures on state: 7ce3188
  • Dispatch no longer has actions bound to it and fixes to types: ff6cd76
  • Removes unused deps and bumps version: 858c96b
  • Adds yarnrc: 0bdbdad
  • Fixes thunk payloads: 8b8bdce
  • Bumps version: bff2d9c
  • Adds test case for state any: 7545e63
  • Breaking change listenTo actions now resolved via callback funciton: 8086cb2
  • Progress on new tutorial: 70287db
  • Updates docs: 4b30b9f
  • Updates website: 754d6a2
  • Website updates: 85e8f7b
  • Fixes useStoreState so that an update gets handled in same render cycle across hook instances: 6f2826f
  • Bumps version: 56c871f
  • Fixes multi hook render cycle issue: 42dc2e1
  • Bumps version: 09ac40f
  • Removes the need to define dependencies on useStoreState: 4cb3ec3
  • Bumps version: cd14db1
  • Removes instance of useStoreState dependencies: 1ff97f7
  • Updates deps: 6145efa
  • Website updates: 75ce14c
  • Reverts the change that removed bound action creators on the stores dispatch: e8aa7bd
  • Fixes action name helper typings: d37943d
  • Bumps version: de12c2c
  • Fixes store so it does not kill class based properties: 1c51bf7
  • Bumps version: b3ad4eb
  • Updates website: 8c4ffa2
  • Installs v3 of ts-toolbelt and bumps version: d926ce3
  • Bumps version: e300c57
  • Creates a simplified immer produce and fixes debug helper: 461d42e
  • Adds an additional test case for typescript generic interface models: 3f82175
  • Bumps version: 7a382e8
  • Adds new listeners APIs as per #247: #251
  • Updates ts-toolbelt.: d93a01c
  • Moves prop-types from peer deps to deps: ca321b2
  • Updates to Typscript 3.5.3: 39b80a3
  • Removes prop-types from dev deps: 88aed9a
  • Upgrades deps: f77cb49
  • Adds a comment to a typescript test case: 925c68c
  • Adds createTypedHooks API back: 3a16e10
  • Bumps version: 332c80b
  • Updates website: b23993a
  • Updates website: 49e4f25
  • Adds the ability to reconfigur...
Read more