juliankrispel/Pollock

API Refactor 'Mutable'

Closed this issue · 6 comments

The Mutable API lacks consistency. To configure a mutable one has to go through various steps, for example:

@delta = new Mutable().setType(new RandomPosition().setRange(-10,10,-10,10))
@delta.cymode = 'irregular'
@delta.upmode = 'linp'
@delta.cycle.setRange(10,50)

Another thing that bothers us is that .cycle is part of the Mutable interface, as it is confusing.

One common pattern in Javascript is to pass a configuration object to the constructor like so:

@delta = new Mutable
    type: new RandomPosition(-10,10,-10,10)
    cymode: 'irregular'
    upmode: 'linp'
    cycleRange: [10,50]

To change properties we could use a similar API to what we've already established in our PublishSubscriber (set, get). The goal is to solve similar things in similar ways so that the API is easier to understand faster:

@delta.set('type', new RandomPosition(-10, 20, -20, 30)).set('cymode': 'irregular')

Maybe

@delta = new Mutable(
     type: new RandomPosition(-10, 10, -10, 10)
     upmode: 'linp'
     cycle: { mode: 'irregular', range: [10,50] }
)

@delta = new Mutable(
     type: new RandomPosition(-10, 10, -10, 10)
     upmode: 'discrete'
     cycle: { mode: 'regular', interval: 15 }
)

I've branched off BaseConstructor. In commit #2259f83 I am removing state since we don't need it anymore. I'm keeping defaults however. Defaults are used to decorate a new instance with public members.

Refactor now near completion in 5c0f97d

What changes do we need to make to merge this into master @GitHuli ?

Closed as the interface has been recently straightened out.
Mutable is now instanted e.g. by

    @sizem = new Mutable
      value: new RandomIntervalNumber new Range(2, 15)
      upmode: 'linp'
      cycle: new RandomIntervalNumber new Range(20, 100)