Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Fix Filter decorator with nested key paths of null #64

Conversation

dbachrach
Copy link
Contributor

There is a bug in the filter decorator when using nested key paths. If the nested key path value is null. The key path one level higher is written. As an example:

const simpleEngine = {
  save(state) {
    console.log('final state:', state);
  }
};

const basicFilteredEngine = storage.decorators.filter(simpleEngine, [
  ['a']
]);

const nestedFilteredEngine = storage.decorators.filter(simpleEngine, [
  ['a', 'first']
]);

const data = {
  a: {
    first: null,
    second: 2
  }
};

console.log('Simple Engine');
simpleEngine.save(data);

console.log('Basic Filtered Engine');
basicFilteredEngine.save(data);

console.log('Nested Filtered Engine');
nestedFilteredEngine.save(data);

This prints out:

Simple Engine
final state: {
    a: {
        first: null,
        second: 2
    }
}
Basic Filtered Engine
final state: {
    a: {
        first: null,
        second: 2
    }
}
Nested Filtered Engine
final state: {
    a: {
        first: {
            first: null,
            second: 2
        }
    }
}

As you can see, when the value of a.first is null, the saved data structure is corrupted.

This PR ensures that a null or undefined value will properly set the state tree.

@michaelcontento
Copy link
Owner

Fixed with working tests in b7bf6e5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants