In the past CanJS typed objects such as CanMap
, DefineMap
, and DefineList
would always eagerly convert objects into observables. For example when you do:
let map = new DefineMap({a: {b: 'c'}});
Then map.a
is also a DefineMap, and is therefore observable.
This changes with DefineObject
, DefineArray
and anything else that uses their mixins, like StacheDefineElement
. These objects do not convert inner values. So:
let props = {a: {b: 'c'}};
let obj = new DefineObject(props);
obj.a === props.a;
This is good in a lot of ways; it helps with performance and prevents attempting to convert objects that you want left alone.
However there are still cases where you would want this sort of recursive observable conversion. So we've created a new type that can be used like so:
import { DefineObject, type, DeepObservableObjectOrArray } from "can";
class Favorites extends DefineObject {
static define = {
options: type.convert(DeepObservableObjectOrArray)
}
}
new DefineObject({ options: {a: {b: 'c'}} });
We need help because we're unsure of what to call this. Some options for consideration with brief explanations:
- Eager: It eagerly converts objects to observables.
- Greedy: Like a greedy regex.
- RecursiveObservable: It recursively converts to observables.
- ToDefineObjectOrArray: This is more direct in what it does, which is convert to DefineObjects, DefineArrays, or leaves alone if primitive types.
- BuiltInOrObservable: Also direct but less wordy.
- Hungry: A type that is hungry, it eats objects and digests them into observables.