Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions icaro.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const ICARO_HANDLER = {
// filter the values that didn't change
if (target[property] !== value) {
if (value === Object(value) && !value[isIcaro]) {
target[property] = icaro(value);
target[property] = icaro(value, target);
} else {
target[property] = value;
}
Expand Down Expand Up @@ -184,9 +184,10 @@ function define(obj, key, value) {
/**
* Enhance the icaro objects adding some hidden props to them and the API methods
* @param {*} obj - anything
* @param {*} parent - parent icaro proxy
* @returns {*} the object received enhanced with some extra properties
*/
function enhance(obj) {
function enhance(obj, parent) {
// add some "kinda hidden" properties
Object.assign(obj, {
[changes]: new Map(),
Expand All @@ -200,6 +201,9 @@ function enhance(obj) {
listeners.get(obj).forEach(function(fn) {fn(obj[changes]);});
obj[changes].clear();
});
if (parent) {
parent[dispatch](parent[changes].size, obj)
}
}
}
});
Expand All @@ -225,11 +229,12 @@ function enhance(obj) {
/**
* Factory function
* @param {*} obj - anything can be an icaro Proxy
* @param {*} parent - should be an icaro Proxy
* @returns {Proxy}
*/
function icaro(obj) {
function icaro(obj, parent) {
return new Proxy(
enhance(obj || {}),
enhance(obj || {}, parent),
Object.create(ICARO_HANDLER)
)
}
Expand Down