Skip to content

Commit

Permalink
Allow falsy values for domData.get
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Frampton authored and Robert-Frampton committed Dec 1, 2017
1 parent ffc5598 commit 402a12e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/metal-dom/src/domData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

import {isDef} from 'metal';

const METAL_DATA = '__metal_data__';

/**
Expand All @@ -21,7 +23,7 @@ class domData {
if (!name) {
return element[METAL_DATA];
}
if (!element[METAL_DATA][name] && initialValue) {
if (!isDef(element[METAL_DATA][name]) && isDef(initialValue)) {
element[METAL_DATA][name] = initialValue;
}
return element[METAL_DATA][name];
Expand All @@ -39,23 +41,18 @@ class domData {
/**
* Sets Metal.js's data for the given element.
* @param {!Element} element
* @param {string=} name Optional Property from the data to be returned.
* @param {*=} value Optional value to the set the requested property
* to if it doesn't exist yet in the data.
* @return {!Object}
* @param {string=} name Property from the data to be set.
* @param {*=} value Value to be set on the element.
* @return {!Object|*}
*/
static set(element, name, value) {
if (!element[METAL_DATA]) {
element[METAL_DATA] = {};
}
if (!name || !value) {
if (!name || !isDef(value)) {
return element[METAL_DATA];
}
if (!element[METAL_DATA][name] && value) {
element[METAL_DATA][name] = value;
} else if (element[METAL_DATA][name] && value) {
element[METAL_DATA][name] = value;
}
element[METAL_DATA][name] = value;
return element[METAL_DATA][name];
}
}
Expand Down

0 comments on commit 402a12e

Please sign in to comment.