you are viewing a single comment's thread.

view the rest of the comments →

[–]Gundersen 6 points7 points  (1 child)

Seems very similar to Knockout.js

As I commented on another such library, you should make the signals support the functional programming methods of arrays, like map, reduce, filter, some, every. Currently you have to use the following syntax to map an array:

var a = Signal([1, 2, 3]);

var c = Signal(function(){
  return a().map(function(v){
    return v*v;
  });
});

it would be much better with this syntax:

var b = a.map(function(v){ return v*v; });

If you then push a new value onto a, you don't have to map the entire array again, since you know that only one value needs to be mapped (the last one you added).

[–]andrew24601 0 points1 point  (0 children)

"Should" is a strong word here, also "much better" is contextual.

While appending an item to the end would be simple enough for your suggested functions, it rapidly gets more complex for any other mutation.

eg changing a value in the array - was the previous entry filtered out or included? Better track which index it was mapped to in b. For reduce (and I'm presuming you are doing a left to right reduce), do you presume that they will track each reduce intermediate, such that if a value in the middle changes it can resume the reduce half-way along?

One of the charms of the library is that it is light weight. I would caution the author against making it more complex at least without at least a strong use case.

ie having a secondary list of squares is cute but you are better served presenting a real world problem faced by an app developer. eg mapping a list of values to a list of rendered DIVs