Skip to content

Commit

Permalink
Do not favor undefined over default values when updating data manager.
Browse files Browse the repository at this point in the history
…Fixes #345
  • Loading branch information
Robert-Frampton authored and Robert-Frampton committed Feb 8, 2018
1 parent 9587189 commit 37b274c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/metal-component/src/ComponentDataManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import {object} from 'metal';
import {isDef, object} from 'metal';
import State from 'metal-state';

const BLACKLIST = {
Expand Down Expand Up @@ -120,7 +120,7 @@ class ComponentDataManager {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (!state.getStateKeyConfig(key).internal) {
if (data.hasOwnProperty(key)) {
if (data.hasOwnProperty(key) && isDef(data[key])) {
state.set(key, data[key]);
} else {
state.setDefaultValue(key);
Expand Down
21 changes: 21 additions & 0 deletions packages/metal-component/test/ComponentDataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,27 @@ describe('ComponentDataManager', function() {
assert.strictEqual('bar', component.bar);
});

it('should not favor undefined values over default values when replacing all non internal data', function() {
component.constructor.STATE = {
bar: {
value: 'initialBar',
},
foo: {
value: 'initialFoo',
},
};

initialConfig = {};
ComponentDataManager.setUp(component, {});

ComponentDataManager.replaceNonInternal(component, {
bar: undefined,
foo: 'newFoo',
});
assert.strictEqual('newFoo', component.foo);
assert.strictEqual('initialBar', component.bar);
});

it('should return state instance', function() {
ComponentDataManager.setUp(component, {});
assert.ok(
Expand Down

0 comments on commit 37b274c

Please sign in to comment.