8000 add internal _coerce function · plotly/plotly.js@642bf28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 642bf28

Browse files
committed
add internal _coerce function
1 parent 5c3be81 commit 642bf28

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/lib/coerce.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ exports.valObjectMeta = {
361361
* as a convenience, returns the value it finally set
362362
*/
363363
exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {
364+
return _coerce(containerIn, containerOut, attributes, attribute, dflt).value;
365+
};
366+
367+
function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
364368
var opts = nestedProperty(attributes, attribute).get();
365369
var propIn = nestedProperty(containerIn, attribute);
366370
var propOut = nestedProperty(containerOut, attribute);
@@ -383,7 +387,10 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
383387
*/
384388
if(opts.arrayOk && isArrayOrTypedArray(valIn)) {
385389
propOut.set(valIn);
386-
return valIn;
390+
return {
391+
value: valIn,
392+
default: dflt
393+
};
387394
}
388395

389396
var coerceFunction = exports.valObjectMeta[opts.valType].coerceFunction;
@@ -397,8 +404,11 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
397404
coerceFunction(valIn, propOut, dflt, opts);
398405
valOut = propOut.get();
399406
}
400-
return valOut;
401-
};
407+
return {
408+
value: valOut,
409+
default: dflt
410+
};
411+
}
402412

403413
/**
404414
* Variation on coerce
@@ -408,11 +418,11 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
408418
* returns false if there is no user input.
409419
*/
410420
exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
411-
var valOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);
412-
413-
var attr = attributes[attribute];
414-
var theDefault = (dflt !== undefined) ? dflt : (attr || {}).dflt;
421+
var out = _coerce(containerIn, containerOut, attributes, attribute, dflt);
422+
var valOut = out.value;
423+
var theDefault = out.default;
415424
if(
425+
valOut !== undefined &&
416426
theDefault !== undefined &&
417427
theDefault !== valOut
418428
) {

0 commit comments

Comments
 (0)
0