Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function observableProp(obj: T, key: K): b.IProp {
if (obj == null) throw new Error("observableProp parameter is " + obj);
let bobx = ((obj as any) as IAtom).$bobx;
if (bobx === undefined) throw new Error("observableProp parameter is not observable: " + obj);
if (bobx === ObservableMapMarker) throw new Error("observableProp parameter is observableMap");
if (b.isArray(bobx)) {
// Does this pays off to cache and/or inline?
return (value?: any) => {
if (value !== undefined) {
obj[key] = value;
}
return obj[key];
};
}
if (Object.getPrototypeOf(bobx) === undefined) {
return (bobx[key] as ObservableValue).prop();
}
bobx = asObservableClass(obj);
let val = bobx[key];
if (val === undefined) {
obj[key]; // Has side effect to create ObservableValue
val = bobx[key]!;
function isArrayLike(thing) {
return b.isArray(thing) || isObservableArray(thing);
}
b.setIsArrayVdom(isArrayLike);
function isArrayLike(thing: any): thing is any[] {
return b.isArray(thing) || isObservableArray(thing);
}
postRender(focused: boolean) {
if (this.parent == undefined) {
this._clear();
return;
}
let ch = this.parent.children;
if (!b.isArray(ch)) {
this._clear();
return;
}
const selectable = this.selectable;
selectable.length = 0;
for (let i = 0; i < ch.length; i++) {
let c = ch[i].ctx as IMenuItemControllerChild;
if (c.owner == this && !c._disabled) {
selectable.push(c);
}
}
this._update(focused);
}
function isObservableArray(thing) {
return isObject(thing) && b.isArray(thing.$bobx);
}
exports.isObservableArray = isObservableArray;
function deepStructEnhancer(newValue, oldValue) {
if (deepEqual(newValue, oldValue))
return oldValue;
if (newValue == null)
return newValue;
if (isObservable(newValue))
return newValue;
if (b.isArray(newValue))
return new ObservableArray(newValue, deepStructEnhancer);
if (isES6Map(newValue))
return new ObservableMap(newValue, deepStructEnhancer);
if (isPlainObject(newValue)) {
var res = Object.create(Object.getPrototypeOf(newValue));
var behind = asObservableObject(res);
for (var key in newValue) {
defineObservableProperty(res, behind, key, newValue[key], deepStructEnhancer);
}
return res;
}
return newValue;
}
function refStructEnhancer(newValue, oldValue) {
export function isObservableArray(thing: any): thing is IObservableArray {
return isObject(thing) && b.isArray(thing.$bobx);
}
function deepEnhancer(newValue: T, oldValue: T | undefined): T {
if (newValue === oldValue) return oldValue;
if (newValue == null) return newValue;
if (isObservable(newValue)) return newValue;
if (b.isArray(newValue)) return new ObservableArray(newValue as any, deepEnhancer) as any;
if (isES6Map(newValue)) return new ObservableMap(newValue, deepEnhancer) as any;
if (isPlainObject(newValue)) {
let res = Object.create(Object.getPrototypeOf(newValue));
let behind = asObservableObject(res);
for (let key in newValue as IKeyValueMap) {
defineObservableProperty(res, behind, key, (newValue as IKeyValueMap)[key], deepEnhancer);
}
return res;
}
return newValue;
}