Skip to content

Commit d2da84f

Browse files
solving conflicts to merge
2 parents 5324ff4 + f332182 commit d2da84f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ export function createPersistMachine(structure, store, debug) {
8989
*/
9090
_map(structure, (object, name) => {
9191
// Catch any errors with the persist configuration
92-
if (_isNil(object.values))
93-
throw new Error("You need to define a `values` array in your persist object.");
9492
if (_isNil(object.key))
9593
throw new Error("You need to define a `key` value to identify your data in your persist object.");
9694
// Get the static key for mapping
@@ -131,6 +129,12 @@ export function createPersistMachine(structure, store, debug) {
131129
* we care about, which are defined in structure.
132130
*/
133131
const newState = _pickBy(state, (value, key) => {
132+
/**
133+
* If nothing is passed to the `values`
134+
* parameter, all values will be used.
135+
*/
136+
if (_isNil(stateValues))
137+
return value;
134138
if (stateValues.includes(key))
135139
return value;
136140
});

lib/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@ export const persistMiddleware = (save: SaveCallback, load: LoadCallback) => (ne
9090
* @param debug - Debug data to the console
9191
*
9292
*/
93-
export function createPersistMachine(structure: any, store: any, debug: boolean) {
93+
export function createPersistMachine(structure : any, store : any, debug: boolean) {
9494
/*
9595
* We do an initial map of the structure
9696
*/
9797
_map(structure, (object: any, name: any) => {
9898
// Catch any errors with the persist configuration
99-
if (_isNil(object.values)) throw new Error("You need to define a `values` array in your persist object.");
100-
if (_isNil(object.key)) throw new Error("You need to define a `key` value to identify your data in your persist object.");
99+
if(_isNil(object.key)) throw new Error("You need to define a `key` value to identify your data in your persist object.");
101100

102101
// Get the static key for mapping
103102
const {
@@ -146,7 +145,13 @@ export function createPersistMachine(structure: any, store: any, debug: boolean)
146145
* Builds a state only containing the values
147146
* we care about, which are defined in structure.
148147
*/
149-
const newState = _pickBy(state, (value: any, key: any) => {
148+
const newState = _pickBy(state, (value : any, key : any) => {
149+
/**
150+
* If nothing is passed to the `values`
151+
* parameter, all values will be used.
152+
*/
153+
if (_isNil(stateValues)) return value;
154+
150155
if (stateValues.includes(key)) return value;
151156
});
152157

0 commit comments

Comments
 (0)