mostjs / hold

Deliver the most recently seen event to new observers
MIT License
30 stars 5 forks source link

hold returns a `MulticastSource` and not a `Stream` #26

Closed note89 closed 7 years ago

note89 commented 7 years ago

https://github.com/mostjs/hold/blob/3ae8107c4974a0c7c40dc8194c8bdf3dbdd45737/src/index.js#L5-L7

Hold returns a MulticastSource and not a Stream like before — is this the intended behavior ?

The change was made in #22 Cheers!

briancavalier commented 7 years ago

Hi @note89. Yep, it's intentional. @most/hold 3.0.0 is compatible with @most/core, where Stream is just a type/interface (flow and TS) and , not a concrete class.

For compatibility with most, use @most/hold 2.0.0. I'll add a compatibility note to the README.

note89 commented 7 years ago

guess the type signature need to update then ? and the readme where it says

Usage

import { fromEvent } from 'most'
import { hold } from '@most/hold'

// start holding on first subscription
const clickStream = fromEvent('click', document)
  .map(e => ({ x: e.clientX, y: clientY }))
  .thru(hold)

// hold the latest event even before the first subscription
clickStream.drain();

API

hold :: Stream a → Stream a

Given an input stream:

stream:    -a---b---c---d->

observers which begin observing at different times will see:

observer1: -a---b---c---d->
observer2:    a-b---c---d->
observer3:           c--d->

The example will not work anymore right ?

briancavalier commented 7 years ago

Hey @note89 You're right about the example. Sorry about that. It needs to be updated to show @most/core usage. I'll fix that.

However, the type signature is correct. The intent is that hold returns a Stream, of which one implementation happens to be MulticastSource, such that callers should depend only on the Stream interface, and not on the implementation details of MulticastSource.

note89 commented 7 years ago

but hold now returns a Source so i get runtime error when I follow the type signature provided https://github.com/mostjs/hold/blob/master/type-definitions/hold.d.ts

export function hold<A>(stream: Stream<A>): Stream<A>;
briancavalier commented 7 years ago

Hmmm, ok. Could you paste the error and example code that produces it? Thanks!

note89 commented 7 years ago

sorry, my bad didn't realize @most/core is a replacement for most. thought it was something most used underneath. so i used @most/hold 3.0.0 with most Is most depricated now?

Thank you very much for the information!

briancavalier commented 7 years ago

Hey @note89 no worries at all. Sorry for the confusion. I'll try to clarify the relationship.

Most 1.x is not deprecated. It will continue to be fully supported until most 2.0 is released.

@most/core is a reimplementation of most's architecture using the lessons we learned from building and maintaining most. It intentionally has a smaller API that is more tailored to a functional style of programming. Most 2.0 will be implemented on top of @most/core.

If you're starting a new project, and @most/core's leaner API, it's programming style seems interesting, and you can tolerate the possibility of small changes before it becomes 1.0, I recommend starting with it rather than most.

I hope that helps! I opened an issue to add this question to a @most/core FAQ.

note89 commented 7 years ago

Thank you very much :) Love most.js use it every day! Hugh thanks for creating such an awesome thing !

briancavalier commented 7 years ago

Thanks, @note89. Glad to hear it's been useful for you :+1: