-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
This leads to non-obvious behavior which I think we need to properly define or change. Here is the implementation as it stands:
class Meta {
getProperty(name, value) {
if (!this.meta[name]) {
this.meta[name] = registry.toType(value);
}
return this.meta[name];
}
}Here is the surprising part:
const element = new ElementType();
console.log(element.toCompactRefract());
// => ['element', {}, {}, null]
// Access the non-existing name property
element.name;
// What? Now there is a meta name for some reason!?
console.log(element.toCompactRefract());
// => ['element', {name: ''}, {}, null]
// Try to get something from meta with a default if not found
element.getProperty('foo', 'bar');
// What? Now my default value is getting serialized!
console.log(element.toCompactRefract());
// => ['element', {name: '', foo: 'bar'}, {}, null]I'm sorry I glossed over this in the initial review! I believe the code is written this way to cache the conversion to refract element classes for the default value, but I think we need to either do that conversion each time or keep a separate cache that doesn't mutate the original meta values..
Thoughts @smizell?