Correct way to push to an array in a model

Antranig Basman antranig.basman at colorado.edu
Wed Apr 4 17:30:39 UTC 2018


Yes, what you've written is OK, although a shallow copy will be 
perfectly fine that is,
curUnsavedChanges = that.model.unsavedChanges.concat([{description: 
description}]) or so.
Yes, there will indeed be new dedicated change types as planned at 
https://issues.fluidproject.org/browse/FLUID-3504 - note that this issue 
is only 8 years old!

This suggests that another scheme for appending to the array would be

that.applier.change("unsavedChanges." + 
that.model.unsavedChanges.length, {description: description});

but of course this is only a reasonable solution for the append case.

On 04/04/2018 18:15, Moss, Gregor wrote:
> 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
>      });
>      h
> 
> 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
> _______________________________________________________
> 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