-
Notifications
You must be signed in to change notification settings - Fork 0
Handle non-plain objects as item values #6
Copy link
Copy link
Open
Description
Problem
item.js currently distinguishes only between primitives and objects:
- primitives → stored as-is
- objects → decomposed into a child-item tree
This breaks for "opaque" objects that shouldn't be decomposed — Date, RegExp, Map, Set, but also custom class instances. While this behavior can be customized via subclassing (Item::isPrimitive()), we want the best default behavior for standard Items.
i.item('date').set(new Date(2024, 2, 10))
i.item('todo').set(otherItem)
// Date gets decomposed into a child-item tree → information lostSetting an Item instance as the value of another item is also ambiguous — should it be decomposed, embedded or thrown?
Considered solution: use toJSON
Objects with a toJSON method would be treated as opaque — toJSON() is called and the result stored as the value. Date has it built-in, custom classes can implement it.
Concerns
- Already too much "magic"?
- A class might implement
toJSONfor a different purpose, with a format that differs from what one would want stored in the item tree — silent, hard-to-debug conflict.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels