react-narrow 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -128,6 +128,20 @@ const settingsStore = createNarrowedStoreContext(appStore, (s) => s.settings)
128
128
  - Components take a slice and a setter as props, so they work with any store and test with plain values, instead of being wired to one global store by path
129
129
 
130
130
 
131
+ ## Reading the pre-edit value in a recipe
132
+
133
+ `original` and `current` are re-exported from Mutative, so you don't need to depend on it yourself. Inside a mutating function, `original(draft)` is the value from before the edit and `current(draft)` is a snapshot of the draft so far. They only work on drafts from the same copy of Mutative that `react-narrow` uses, which is why they come from here.
134
+
135
+ ```ts
136
+ import { original } from 'react-narrow'
137
+
138
+ // Only apply this write if the slice hasn't been replaced since `basis` was read
139
+ setSlice((s) => {
140
+ if (original(s) !== basis) return
141
+ s.title = result
142
+ })
143
+ ```
144
+
131
145
  ## Narrowing to an item picked at runtime
132
146
 
133
147
  Give the narrow function a second parameter, and pass it to the Provider:
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export type { SetStore, Narrower } from './store.js';
2
2
  export { useNewStore, useNarrowedStore, NarrowList, createContextStore, createNarrowedStoreContext, } from './react.js';
3
3
  export type { ContextStore, StoreContext } from './react.js';
4
+ export { original, current } from 'mutative';
5
+ export type { Draft } from 'mutative';
package/dist/index.js CHANGED
@@ -1 +1,4 @@
1
1
  export { useNewStore, useNarrowedStore, NarrowList, createContextStore, createNarrowedStoreContext, } from './react.js';
2
+ // Re-exported so recipes always use the same Mutative copy as the library: `original()` and `current()` only
3
+ // accept drafts created by the copy that made them.
4
+ export { original, current } from 'mutative';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-narrow",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",