Lazy Reactivity #6
Replies: 2 comments 1 reply
-
Perhaps adoption APIs should allow a callback parameter You allow the consumer to choose if they want to implement wild recursive semantics, but your framework isn't providing it directly. The framework already owns responsibility for "special reactivity magic happens on property access"... is this too much scope creep? interface Block {
id: string,
title: string,
children: Block[]
}
const adoptArrayOfBlock: PropertyAdopt<Array<Block>> = (prop, val) =>
reactive.adopt.object(val, adoptBlockProperty)
const adoptBlockProperty: PropertyAdopt<Block> = (prop, val) =>
prop === 'children'
? reactive.adopt.array(value, adoptArrayOfBlock)
: val
const reactiveBlock = reactive.adopt.object(block, adoptBlockProperty) |
Beta Was this translation helpful? Give feedback.
-
Over in ember-land, I made something that sounds similar -- I just called it idk if that's the approach you'd want to take, but I imagine the starbeam equivalent could be something like: const lazilyWrappedArray = reactive.array.map(inputArray, (element) => new WrapperThing(element)); initially, nothing would happen other than the wrapper object/class is created. let first = lazilyWrappedArray[0];
// or
let nth = lazilyWrappedArray[n]; then the first and nth objects only would be wrapped in This object can also define an iterator so that for (let wrapped of lazilyWrappedArray) {
} works, and if you Caveats:
|
Beta Was this translation helpful? Give feedback.
-
If you have a large array of objects and want to turn it into a reactive array of reactive objects, you'd probably do something like this:
This would eagerly convert your entire array into a reactive array of reactive objects.
But, in similar use cases as the incoming adoption API, you may want an array that incrementally adopts entries in the array as they are accessed.
I think this is a natural extension of
reactive.array
, and I'm sticking the idea here for discussion. I'll follow up once adopting reactive objects has landed.Beta Was this translation helpful? Give feedback.
All reactions