juliankrispel / Pollock

A canvas-based application which paints by itself.
2 stars 1 forks source link

API Refactor 'Mutable' #22

Closed juliankrispel closed 10 years ago

juliankrispel commented 10 years ago

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.

juliankrispel commented 10 years ago

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')
ulikk commented 10 years ago

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 }
)
juliankrispel commented 10 years ago

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.

juliankrispel commented 10 years ago

Refactor now near completion in 5c0f97d62db2522ceb86f0dde4d5e247ce33c23d

juliankrispel commented 10 years ago

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

ulikk commented 10 years ago

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)