Easy Peasy Versions Save

Vegetarian friendly state for React

v3.2.2

4 years ago

Patches

  • Minor improvement to types: 16c7d13af9d7eab1256c810556d02fd192e2562a
  • Small fix on mergeDeep strategy for persistence rehydration: 38de8693a3af928f11ed4cdab68f07828034413b
  • Adds more TS test coverage: 01fd077a773e7294650970f3d31576b74adbcc9f
  • Updates deps: 5e033e29aebf1ae022a6221a05d76b063b19ae70

v3.2.1

4 years ago

Patches

  • Fixes typescript issue with generics and actions: bd9e978fe5000701dc80ce1e5501f8a083fb976d

v3.2.0

4 years ago

Minor Changes

  • Adds store persistence APIs: #343

Patches

  • Fix docs: 2ce5f1afe2b80c7b2b9e2e7f0bb53882749b6bf4
  • Updates website: 627fd17f5fdce4630f6837bd482c48f4a8d980cd

v3.1.2

4 years ago

Patches

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

v3.1.1

4 years ago

Patches

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

v3.1.0

4 years ago

Minor Changes

  • Adds useStore hook: e128e1e09ada612c623bad3d43023fdb23ac982b

Patches

  • Fixed some lint issues: 740d1a42da8de0219f76b8832e7f73bf86f87aa0
  • Update testing-actions.md: 52a85611d565632db937889fcd33b2b4557bfd78
  • 📝 Add comma at action listener example: 5963568b968df33afc14829f94978f0b8e78d4c4
  • Update adding-typed-actions.md: c92ff7c88c37e7f70823c6015ab9211326b3e819
  • Update adding-typed-thunks.md: e0ddb220ab439fec1f5b3f4565979542221ff9df
  • Fix: added html suffix to store links within docs;: d3cc2b581a28d5e80a0be1762b538a685cf33af6
  • Reduce the number of mapped types used in state mapper: 66da0415405198a9bba08eaca8ac41a224921d33
  • Prevent state updates on unmounted components: 65a2fd879a08416643b3dbcbcaae5c39fbb4540c
  • Minor tweak to typescript state mapper: c4efa4f59be8abe72c888d3decb32002f7dcbe50
  • Upgrades dependencies: ea8aa83a2f0cf705644ce8d5c5fed408693d9793
  • Adds generic model typescript case: 08ab8d955810966319ddc3842e4df8a9142e1b4c

v3.0.2

4 years ago

Patches

  • Updates deps: ee424b49ece394d8ce7f59564be54161102e9592
  • Adds warning about invalid computed property access: 6992dc9c13c244bc6c260bd33ac45b1a7c6d0df8
  • Bumps deps and version: a4202a7be34d3c93c218158066bbac437fd3ad12

v3.0.1

4 years ago

Patches

  • Upgrades deps: 6becae18adff531d0b6469487cae06de6d6672c7

v3.0.0

4 years ago

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: f5fbe87a24cae600183ddbd2fe35036a6c7141c2
  • Removes deprecated code: ba955a5fb55f58a4943f6770d8d48d11f9ce2464
  • Removes unused assets: 0a06ee84778af47386acb6782c50c89ee7ae4648
  • Cleans up and organises the typescript definitions: 78dc4d4866d24c126b864a023df939a0281b1410
  • Adds depth limit to State and Actions typescript definitions: 55375dcb746e2e79eea3f27ff27b541642e954a8
  • Fixes index signatures on state: 7ce3188294774785555a99e8b14881267700cd26
  • Dispatch no longer has actions bound to it and fixes to types: ff6cd76abfc5010b48a8442a7ceaa0ca82159095
  • Removes unused deps and bumps version: 858c96b461eebe28de6f363a6081f577db758122
  • Adds yarnrc: 0bdbdad75250ab25cb506bf7c9090605ba83e8ad
  • Fixes thunk payloads: 8b8bdce969de70ef55df9ed23811f9fc5badab8c
  • Bumps version: bff2d9c64d2ea296ec85fc365b173abcd70623ff
  • Adds test case for state any: 7545e63b5827c40a484c84d3543c218f06672786
  • Breaking change listenTo actions now resolved via callback funciton: 8086cb2dccac773ce82e814ea3bbe852dd261a44
  • Progress on new tutorial: 70287dba3150aec5f217d79c5928194176dc7bc1
  • Updates docs: 4b30b9f4c2f9faf2a4fb54d9f897e043f2c3e837
  • Updates website: 754d6a29b76d511cb411ab9e24808776df294417
  • Website updates: 85e8f7b9d36b39671176d5894e310be316dfb024
  • Fixes useStoreState so that an update gets handled in same render cycle across hook instances: 6f2826f22d4f4b0ac5be7f9df114cd5ca323136d
  • Bumps version: 56c871f31b6a01e8e42c985b1c1696036ab019f9
  • Fixes multi hook render cycle issue: 42dc2e1c9431071f996db7c43a61289b42cbe08c
  • Bumps version: 09ac40fe4748ba44662f8d6e857bf1d76893e796
  • Removes the need to define dependencies on useStoreState: 4cb3ec383f8a2cd0675d10aed077bd3890880064
  • Bumps version: cd14db134962b7aa4b5357cced28655d5a227500
  • Removes instance of useStoreState dependencies: 1ff97f7f83a3fea134df67b2ae62d0d46880caef
  • Updates deps: 6145efa3082df76e2b9e4d1560ce5bd5d49d96c5
  • Website updates: 75ce14cc1460395735c48b4754f54f2005fcc5eb
  • Reverts the change that removed bound action creators on the stores dispatch: e8aa7bdbc647302c915d8a34e4eae1982f9f0804
  • Fixes action name helper typings: d37943d26b14e368fbf4fb0f40c26c3d314919b4
  • Bumps version: de12c2cbec0780c37cb891f24651147f4e95f5ec
  • Fixes store so it does not kill class based properties: 1c51bf7c5c521429561d5f1ee9cd11e54dd91833
  • Bumps version: b3ad4eb761417d5aa938487bed5ef859b5d75b97
  • Updates website: 8c4ffa251938002cfffa02c53504ec460a5215bb
  • Installs v3 of ts-toolbelt and bumps version: d926ce35e141636e3897056c2ad21a4ee37f0617
  • Bumps version: e300c57a24dc3ab325441fc8e6f2aabc0e29eede
  • Creates a simplified immer produce and fixes debug helper: 461d42e150a5531268fb2aee063bc92b589f04ca
  • Adds an additional test case for typescript generic interface models: 3f82175fde1ec4a9a2baa23a754f11deeaff0a18
  • Bumps version: 7a382e8683478bcf945a8c421a7fefe631904304
  • Adds new listeners APIs as per #247: #251
  • Updates ts-toolbelt.: d93a01c53b85314ba1d8810d6d360e425bcbd762
  • Moves prop-types from peer deps to deps: ca321b20b6da243978ac0367579e27bda6c184d5
  • Updates to Typscript 3.5.3: 39b80a31a138502f72431d7c82b6c5c604ed7775
  • Removes prop-types from dev deps: 88aed9aec8013bb110badaba0749da7dd56e7714
  • Upgrades deps: f77cb4988992a0371f92e15035ab3b14ee03a23e
  • Adds a comment to a typescript test case: 925c68c5194bbcf8971552a9a443b800e6b3ff4e
  • Adds createTypedHooks API back: 3a16e10fafe16ef79ac06cb6640a7b6107f2d1f2
  • Bumps version: 332c80bcebdfee32eb28670c624a21586f820bd3
  • Updates website: b23993ae4e96f871aba0ae0dd653fbacec88bfb5
  • Updates website: 49e4f251a90d117996546152a7fbf60bad13a9dc
  • Adds the ability to reconfigure a store: 270dc6a9b69b27e9c4856b1835db1e8c68c6eb58
  • Bumps version: 80112daf8ee681b851a4949ece0deac96f3c8cbd
  • Updates website: 809c278e96b03589e879316ed49f61c0873578b2
  • Updates website: dfc4209bd57d278488a764dd5b58a7602fdabce1
  • Updates website: 68721b8c27a998200991e227b0a8d5b1d55e9a29
  • Updates website: 58204ffef7d125dc2253cb47b155506ad81440f1
  • Updates website: 9f3152bd1c70bba24fc742f7710675543deba2c3
  • Adds now deploy config: 0eada962985b8e05f0f4b7c1c2fd3670bdb31a7c
  • Removes the hooks from store instance: 49ee9e3c221c5244973ea468d83cfe4638008f4e
  • Updates website: 9261d2334196e95176dcd9903c23ced81f7d33f2
  • Bumps version: 9e519d0b5ed3e8c18e59703c0f26e00f214da7f6
  • Updates website: 672e7863c35b3bc308d6c6ad8ecdc08d42c23de5
  • Adds tests and docs about testing: 06e67acd296d2d6634936af896b369dc1b928f79
  • Adds 100% code coverage: d35153c565ee15fd4e9273937160b61c1f7b0eb3
  • Code housekeeping: 95eb5ef7389af754aca2b08f8628ad09d7f96e85
  • Updates website: bee0ad6913f268c97328a38d2264dad4af53cb54
  • Bumps version: e4859b91d1adaa8609fbc36a87969ee1947fc7c0
  • Updates website: 0efd3d02a41b720271f27fd8ad8bc9911d5fc404
  • Updates readme: 2be472b8169a320658cbb68f844a56522e9147d8
  • Refactor listener TS api: #259
  • Type experiment: 17f82155c2499d2129d03ff6e64285240d9ab7fa
  • Refactors computed and simplifies the TS defs for it.: 13526ba056edf94cfc56285af9bef9eac7ca090a
  • Updates docs: 9f4f8ccbbff8b00325e7c33dd21b76c348e38abe
  • Bumps version: 0646512e8f2d55dfe712158d7e00ddcef9773e27
  • Enables disabling of immer: ada83d750ae29018f5ac7464c9e00cd33efd546b
  • Code cleanup and refactoring. Listeners correctly prefixed: 292804f64627a4ace0cb2aef099c528609a058c2
  • Moves listeners into a getListeners API of the store instance: c9ee9d88effb28a64042aa83aa89e62378689670
  • Updates documentation per new getListeners: 2706d2212dc86319baf4fc0ccdf884286815e60e
  • Fixes disableImmer behaviour: 5ae789aa59d7ffd73a0578f66c29e01f6e917ab7
  • Bumps version: 7c97880079f6f41b41ced87285e122f2e36f2b0f
  • Updates release number in docs: 6147021dc9c8573366783cc5f37cf4ceeac02f41
  • Minor docs update and definition fix: dfaf0cc2cb8633a06ac94a8e12bf65de9a7a3da0
  • Updates website: 9f221da2564b8f3a0da9a6d3b8f4b389fe755ffa
  • Bumps version: 6efd17e691c3c0a1e66657f7e80313dba8010480
  • Bumps version: 961a4fc431c4a8212134028b05e59830e2cb8e67
  • Converts thunks so that they can be asynchronous or synchronous: c465d983ebbe61901ddcda5339d7f6d350a79e75
  • Upgrades deps: 78923e359c1e9b8fd7026b9d251fcede9d357b7c
  • Fixes computed property reducer access cases: d9aa1823a82aa61a465ec40a5b470d7ef5fbedc8
  • Updates deps: 412c77fd534df1555c071ecd7ac5c050345b0f50
  • V3: a297302077554fbb42f092a889c5be1626c36f01

v2.6.5

4 years ago

Patches

  • Updates typescript definitions to play a bit nicer with generic model interfaces: f526916e25f39cb15992aafe86d2d95470d7a815
  • Updates to stable immer-peasy: 3144e24188d8b4ade01ab918da8cdabaa5f2e2a4