0

I've been playing around with the positioning Famo.us course: http://famo.us/university/famous-101/positioning/

On page 4 they talk about chaining modifiers. Why is it not possible to reuse the same modifier more than once?

I tried the following code from the example:

mainContext
  .add(translateModifierOne)
  .add(rotateModifierOne)
  .add(redSurface);

mainContext
  .add(rotateModifierTwo)
  .add(rotateModifierOne)
  .add(translateModifierTwo)
  .add(greySurface);

mainContext
  .add(rotateModifierTwo)  
  .add(greySurface);

Inspecting the DOM, I only see a single .

Thanks,

JD

Joseph Carroll
  • 465
  • 6
  • 15

2 Answers2

0

To answer my own question:

The reason only a single div appears is due to the Modifier maintaining a single state:

Modifier.prototype.modify = function modify(target) {
    _update.call(this);
    **this._output.target = target;**
    return this._output;
};

It would be really cool if the Modifier could support an array of targets!

Joseph Carroll
  • 465
  • 6
  • 15
  • Unusual (well, pointless really) to use a named function expression then not use the name. Also given their issues with IE. – RobG Sep 06 '14 at 00:59
  • Not sure I follow.. I'm a JavaSE developer and this is my first foray into JavaScript. Could you clarify some? – Joseph Carroll Sep 06 '14 at 22:26
  • In `Modifier.prototype.modify = function modify(target) {...)` the right hand side is a [*function expression*](http://ecma-international.org/ecma-262/5.1/#sec-11.4.3) with an optional name. The name is supposed to only be available within the function, so if it's not used there, then there is no point in having it. Also, some browsers (incorrectly) make the name a global variable. Further reading: [*Named function expressions demystified*](http://kangax.github.io/nfe/). – RobG Sep 07 '14 at 23:02
0

I explain in this answer with examples why you cannot re-use Modifiers

It also shows how a modifier will have an effect on multiple renderables by adding those renderables to a view (Render Node) and chained to the Modifier.

Community
  • 1
  • 1
talves
  • 13,993
  • 5
  • 40
  • 63