@intelligo.ai/bonfire
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -54,26 +54,49 @@ import onChange from 'on-change'; | ||
} | ||
export function WithObservable() { | ||
export function WithObservable(observableKey) { | ||
return function (target, key) { | ||
var newKey = key + "$"; | ||
var newKeyProxy = "___" + key + "$$$"; | ||
var handleChange = function (path, value, perValue) { | ||
if (value !== perValue) { | ||
target[newKeyProxy] = onChange({ value: target[newKeyProxy].value }, handleChange); | ||
target[newKey].next(target[newKeyProxy].value); | ||
} | ||
var pKey = observableKey || key + "$"; | ||
var proxyKey = "proxy__key__" + key; | ||
var init = function (isGet) { | ||
return function (newVal) { | ||
var _this = this; | ||
var handleChange = function (path, value, perValue) { | ||
if (value !== perValue) { | ||
_this[proxyKey] = onChange({ value: _this[proxyKey].value }, handleChange); | ||
_this[pKey].next(value); | ||
} | ||
}; | ||
Object.defineProperty(this, key, { | ||
get: function () { | ||
return _this[proxyKey].value; | ||
}, | ||
set: function (val) { | ||
var value = val; | ||
if (!_this[pKey]) { | ||
_this[pKey] = new BehaviorSubject(val); | ||
} | ||
if (_this[proxyKey]) { | ||
_this[proxyKey].value = val; | ||
} | ||
else { | ||
value = val; | ||
_this[proxyKey] = onChange({ value: value }, handleChange); | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
if (isGet) { | ||
return this[key]; // get | ||
} | ||
else { | ||
this[key] = newVal; // set | ||
} | ||
}; | ||
}; | ||
target[newKeyProxy] = onChange({ value: target[key] }, handleChange); | ||
target[newKey] = new BehaviorSubject(target[key]); | ||
var get = function () { | ||
return target[newKey].value; | ||
}; | ||
var set = function (value) { | ||
target[newKeyProxy] = onChange({ value: value }, handleChange); | ||
target[newKey].next(target[newKeyProxy].value); | ||
}; | ||
Object.defineProperty(target, key, { | ||
configurable: true, | ||
// Override property to let init occur on first get/set | ||
return Object.defineProperty(target, key, { | ||
get: init(true), | ||
set: init(false), | ||
enumerable: true, | ||
get: get, | ||
set: set | ||
configurable: true | ||
}); | ||
@@ -80,0 +103,0 @@ }; |
export declare function ReRenderOnChange(): (target: any) => any; | ||
export declare function SetChecker<J = any>(): (target: Object, key: string) => void; | ||
export declare function WithObservable<T = any>(): (target: Object, key: string) => void; | ||
export declare function WithObservable<T = any>(observableKey?: string): (target: any, key: string) => any; |
{ | ||
"name": "@intelligo.ai/bonfire", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Open source decorators utils for angular", | ||
@@ -5,0 +5,0 @@ "main": "./dist/lib/index", |
@@ -9,7 +9,4 @@ ![alt text](https://i.imgur.com/fRpDEDh.png) | ||
Bonfire is open source decorators utils for angular. | ||
Bonfire is a set of utilities decorators in Angular designed in order to make code more intuitive and efficient when it comes to tracking changes in the data. It helps implementing the OnPush strategy in an efficient and easy way in order to maintain high performance in those cases. | ||
- Make change detection easy | ||
- Makes Observable for you | ||
You can make your code cleaner and simpler with adding just 2 decorators to your code. | ||
@@ -21,2 +18,4 @@ We know that angular change detection is not simple if you want it to be officiant. So I made Bonfire. | ||
[Meduim post with examples and gifs](https://medium.com/@tzachbonfil/bonfire-its-easy-to-make-your-app-better-84350b6e24e7) | ||
## Installation | ||
@@ -23,0 +22,0 @@ |
Sorry, the diff of this file is not supported yet
11762
106
96