material-motion / material-motion-js

Reusable gestural interactions in JavaScript. In development.
Apache License 2.0
290 stars 26 forks source link

Prevent dragSystem from having multiple connections #219

Closed appsforartists closed 7 years ago

appsforartists commented 7 years ago

Problem

drag$.subscribe(one);
drag$.subscribe(two);

sends multiple observers through the connect function, which means draggable.state is written to repeatedly, which means you can't rely on state.read() to give you the state from the last move.

Potential solutions

  1. Only write to a property if its value hasn't changed, and allow multiple connections
  2. Create a new variable called prevState that remembers the last value from state in connect's closure, so writes to state always have the same value, and make observers dedupe() state if they care about uniqueness.
  3. Create a _multicast() operator, that serves the same observer-pooling use as _remember() without lastValue
    • Perhaps there could be a MemorylessSubject that serves this purpose, and instead of returning a new MotionObservable, _multicast() returns MotionMemorylessSubject.
    • MotionSubject would then be MemorylessSubject + memory
    • _remember() would return a MotionSubject
    • MotionMemorylessSubject would also be useful for distributing cancelation signals between gestural interactions - perhaps it should be called MotionChannel?
    • Alternatively, can just take a rememberLastValue flag in both _remember and IndefiniteSubject and use that to condition observer.next(lastValue). _remember is then sugar for _multicast(true)
appsforartists commented 7 years ago

🎊 My diff is ready for review at http://codereview.cc/D3176