canjs / can-stream-kefir

Stream values into and out of computes
https://canjs.com/doc/can-stream-kefir.html
MIT License
3 stars 2 forks source link

Static compute stream API ~13 #3

Closed justinbmeyer closed 8 years ago

justinbmeyer commented 8 years ago

Related to #2, but only focusing on the static API exported from this module.

toStream use cases:

Pros:

Cons:

computeStream.toStream(compute) //-> stream that emits with compute value #1

.toStream( * , propName, [eventName])

computeStream.toStream(map, "tasks") 
       //-> stream that emits with `tasks` property changes #2a + #3a

computeStream.toStream(map, "foo.bar") 
      //-> stream that emits when `bar` changes on 
      //     `foo` or `foo` changes with a different `bar`.
      //     #2b
computeStream.toStream(map, "tasks","add") 
      //-> stream that emits with `tasks`'s "add" event dispatches
      //     #3b
computeStream.toStream(map, ".", "closed"); 
    //-> stream that emits with `closed` event on `map` #3a

.toCompute(stream)

computeStream.toCompute(stream) //-> compute that changes with `stream.valueOf`

Proposal 2 - closer to event stream expectations

Pros:

Cons:

computeStream.toStream(compute) //-> stream that emits with compute value

.toStream( * , eventName )

computeStream.toStream(map, "tasks") 
         //-> stream that emits with `tasks` event.  
         //    This will commonly be when `tasks` changes.
         // #2a + #3a 
computeStream.toStream(map, "closed")  //#3a
computeStream.toStream( compute(map,"foo.bar"), "change" )
         //-> stream that emits when `foo` or `bar` changes. #2b by way of #1

.toStream( * , propertyName, eventName )

computeStream.toStream(map, "tasks","add") 
      //-> stream that emits with `tasks`'s "add" event dispatches
      //     #3b

Proposal 3 - spaces and dots

Pros:

Cons:

computeStream.toStream(compute)  //#1

computeStream.toStream(obj, "tasks") //#2a
computeStream.toStream(obj, "foo.bar") //#2b

computeStream.toStream( obj, "close") //#3a
computeStream.toStream(obj, "tasks add") //#3b
computeStream.toStream(obj, "person.tasks add") //#3b

Alternate, force people to use . for property reads.

computeStream.toStream(compute)  //#1

computeStream.toStream(obj, ".tasks") //#2a
computeStream.toStream(obj, ".foo.bar") //#2b

computeStream.toStream( obj, "close") //#3a
computeStream.toStream(obj, ".tasks add") //#3b
computeStream.toStream(obj, ".person.tasks add") //#3b

Proposal 4 - To each his/her own

.toStreamFromCompute

.toStreamFromPropery(obs, propName )

.toStreamFromEvent(obs, event)

.toStreamFromEvent(obs, propName, event)

justinbmeyer commented 8 years ago
computeStream.toStream(obj, ".fullName") //#2a
computeStream.toStream(obj, "fullName") //#3a
obj = {
  get fullName() {
    Observation.add(this, "first")
    Observation.add(this,"last")
    return this.first + " " + this.last;
  } 
}