Skip to content

TypeError: 'set' on proxy: trap returned falsish for property #20

Closed
@xeaone

Description

@xeaone

Hello awesome polly! Got an error not sure if it is me but it only happens when I use strict;. I am not adding a new path just editing existing path. If it is a bug lets see if we can fix it. If it is me slap me in the face but tell me what I am doing wrong please.

error: TypeError: 'set' on proxy: trap returned falsish for property 'port'

Example

'use strict'; // this makes the error throw

function ObserveObject(object, callback) {
    function createProxy(prefix, object) {
        return new Proxy(object, {
            set: function(target, property, value) {
                target[property] = value;
                callback(prefix + property, value);
            },
            get: function(target, property) {
                var value = target[property];

                if (isObject(value)) return createProxy(prefix + property + '.', value); 
                else return value; 
            }
        });
    }

    return createProxy('', object);
}

function isObject(value) {
    if (value === null || value === undefined) return false;
    else return value.constructor === Object;
}

var o = {
    hello: 'blue',
    app: {
        env: {
            port: 7777,
            la: 1
        }
    },
    more: 'stuff'
};

var m = ObserveObject (o, function(path, value) {
    console.log(path);
    console.log(value);
});

m.app.env.port = 8888;
console.log(m);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions