Open
Description
Quoting the README:
(A)
- an exception is thrown if 'trait' contains
required
properties.
(B)
- an exception is thrown if 'trait' contains
conflict
properties.
However, when my prototype provides (or "implements") the required property, an exception is not thrown even though the composed trait contains required
properties.
Snippet 1
const T1 = Trait({ a: Trait.required, b: 1 });
const T2 = Trait({ c: 2 });
const prototype = { a: 0 };
const instance = Trait.create(
prototype,
Trait.compose(
T1,
T2
)
);
// { a: 0, b: 1, c: 2 }
This, though, seems to be inconsistent with "conflicting" properties mechanics (ok, statement (B) holds here, i.e. exception not thrown because the composed trait does not contain conflict
properties).
Snippet 2
const T1 = Trait({ a: 42, b: 1 });
const T2 = Trait({ c: 2 });
const prototype = { a: 0 };
const instance = Trait.create(
prototype,
Trait.compose(
T1,
T2
)
);
// { a: 42, b: 1, c: 2 }
Is this by design?
I would expect something more like:
- an exception is thrown if 'instantiation' contains required properties.
- an exception is thrown if 'instantiation' contains conflicting properties.
...in which snippet 1 is OK because the required a
property is provided by the prototype, and snippet 2 should throw because property a
in the composed trait and in the prototype are conflicting :)
Metadata
Metadata
Assignees
Labels
No labels