Correct way to push to an array in a model
Steven Githens
swgithen at mtu.edu
Tue Apr 3 21:07:40 UTC 2018
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
More information about the fluid-work
mailing list