Correct way to push to an array in a model
Moss, Gregor
gmoss at ocadu.ca
Wed Apr 4 17:15:18 UTC 2018
Hi all,
I'm also interested in seeing what the "right" way to handle such a situation is. I recently encountered a case which was similar. I needed to create a fresh array and then add that to a model path, though I will almost certainly need to make modifications to that path in the future so some shorthand to accomplish that would be great.
Cheers,
Gregor
-----Original Message-----
From: fluid-work <fluid-work-bounces at lists.idrc.ocad.ca> On Behalf Of Steven Githens
Sent: April 3, 2018 17:08
To: Fluid Work <fluid-work at fluidproject.org>
Subject: Correct way to push to an array in a model
Hi Fluid,
Just popping in to check on the correct way to push a value to an array using the change applier.
In the snippet below, I assume using fluid.copy is the correct way to do this, so I'm not editing the model in place outside of the change applier.
var curUnsavedChanges = fluid.copy(that.model.unsavedChanges);
curUnsavedChanges.push({
description: description
});
that.applier.change("unsavedChanges", curUnsavedChanges);
Do we think in the future we might have a few change applier types that could deal with something like this so it's not necessary to copy the item ( even in the future where models are immutable data structures ).
So you might go like:
that.applier.change("unsavedChanges", { description: description}, "ARRAY_PUSH");
And if unsavedChanges wasn't an array it would maybe fail, complain, or just assign it if the current val is a primitive.
Cheers,
Steve
_______________________________________________________
fluid-work mailing list - fluid-work at lists.idrc.ocad.ca To unsubscribe, change settings or access archives, see https://lists.idrc.ocad.ca/mailman/listinfo/fluid-work
More information about the fluid-work
mailing list