[added] subscribe sugar
ClosedPublic

Authored by appsforartists on Oct 3 2017, 1:14 AM.

Details

Summary

As described in the comment, this makes declarations easier to read by identifying what is being written to before the expression that writes to it.

subscribe({
  sink: itemOpacity$,
  to: someSpring.value$.inverted().rewriteRange({
  	fromStart: .5,
  	fromEnd: 1,
  	toStart: .33,
  	toEnd: .67,
	})
})

is more skimmable than the current

someSpring.value$.inverted().rewriteRange({
	fromStart: .5,
	fromEnd: 1,
	toStart: .33,
	toEnd: .67,
}).subscribe(itemOpacity$)

I shied away from property as a key, since the read() and write() methods that differentiate a property from a subject aren't needed here. Moreover, I wanted to make it clear that the value being written to must be an observable (not what some other library/framework might also happen to call a property).

In functional reactive programming, sink is a commonly used to mean the final destination written to by a stream chain; for instance, Cycle.js calls its destinations sinks. An alternative key could be observer.

Diff Detail

Repository
R13 material-motion/material-motion-js
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
appsforartists created this revision.Oct 3 2017, 1:14 AM
Restricted Application added a reviewer: O2: Material Motion. · View Herald TranscriptOct 3 2017, 1:14 AM
Restricted Application added a project: Material Motion. · View Herald Transcript
Restricted Application added a reviewer: O3: Material JavaScript platform reviewers. · View Herald Transcript
Restricted Application added a reviewer: Material Motion. · View Herald Transcript
Restricted Application completed building Restricted Buildable.Oct 3 2017, 1:17 AM

I wonder if source is a better name than to. to sounds like it's being written to, not read from.

featherless requested changes to this revision.Oct 6 2017, 1:55 PM
featherless added a subscriber: featherless.

source is probably better. Or stream?

This revision now requires changes to proceed.Oct 6 2017, 1:55 PM
appsforartists requested review of this revision.Oct 6 2017, 1:59 PM

Agreed. Made that change in http://codereview.cc/D3390

This revision now requires changes to proceed.Oct 6 2017, 1:59 PM
featherless accepted this revision.Oct 6 2017, 2:18 PM
This revision is now accepted and ready to land.Oct 6 2017, 2:18 PM
This revision was automatically updated to reflect the committed changes.