addWires method for adding wires to non-DisplayObject objects

Hi Dan.
We are trying to update our version of ZIM, and I ran into the following problem. In ZIM016, in order to add a wire between two non-ZIM objects, ZIM offers the addWires() method. However, it does not seem to be working for me. This is my code:

const person = {age: 30, name: "John Smith"};

const displayObjParams = {
    label1:{
        color: red,
        text: "-- before wire has effect --",
        size: 25
    },
    label2:{
        color: blue,
        text: "--before wire has effect--",
        size: 30
    }
}

addWires(person).wire({
    input: "age",
    target: displayObjParams.label1,
    prop: "text"
}).wire({
    input: "name",
    target: displayObjParams.label2,
    prop: "text"
});

new Label(displayObjParams.label1)
   .centerReg()
   .pos({horizontal:CENTER, x:-150});
new Label(displayObjParams.label2)
   .centerReg()
   .pos({horizontal:CENTER, x:150});

The resulting labels show that the "text" properties of the displayObjParams objects have not been changed, even though "wire" has been called to change them. Am I doing something wrong?
Thanks!

The wire would have to go on the Label - not the config object. The config object is used once to configure a ZIM object. Once the ZIM object is made, changing the config object does not change the ZIM object.

Also, we are needing to fix the addWires() so that ZIM DUO config objects on the wire() and wired() can be used. Currently they can't. It was something we noticed just recently and have on our list. So for now, use regular parameters.

const person = {age: 30, name: "John Smith"};

const displayObjParams = {
	label1: {
		color: red,
		text: "-- before wire has effect --",
		size: 25
	},
	label2: {
		color: blue,
		text: "--before wire has effect--",
		size: 30
	}
};

const l1 = new Label(displayObjParams.label1)
	.centerReg()
	.pos({horizontal: CENTER, x: -150});
const l2 = new Label(displayObjParams.label2)
	.centerReg()
	.pos({horizontal: CENTER, x: 150});

addWires(person)
	.wire(l1, "text", null, null, null, null, "age")
	.wire(l1, "text", null, null, null, null, "name");

timeout(1, () => {
	person.age = 10;
});
1 Like

thanks!!

1 Like