0no-co / wonka

🎩 A tiny but capable push & pull stream library for TypeScript and Flow
MIT License
709 stars 29 forks source link

fix: subscription closed does not comply with proposal #151

Closed naporin0624 closed 1 year ago

naporin0624 commented 1 year ago

Thank you for creating a great lightweight library.

I have fixed the difference between proposal-observable and the closed type in subscription.

The following are subscription types for proposal-observable.

interface Subscription {

    // Cancels the subscription
    unsubscribe() : void;

    // A boolean value indicating whether the subscription is closed
    get closed() : Boolean;
}

Current wonka subscription type.

interface ObservableSubscription {
  /** A boolean flag indicating whether the subscription is closed.
   * @remarks
   * When `true`, the subscription will not issue new values to the {@link ObservableObserver} and
   * has terminated. No new values are expected.
   *
   * @readonly
   */
  closed?: boolean;
  /** Cancels the subscription.
   * @remarks
   * This cancels the ongoing subscription and the {@link ObservableObserver}'s callbacks will
   * subsequently not be called at all. The subscription will be terminated and become inactive.
   */
  unsubscribe(): void;
}

Confirmed

kitten commented 1 year ago

Nice catch! I think I can see how I made this mistake. I think I wrote it as optional because of ObservableLike for fromObservable to make that type more flexible 🤔

Would you mind updating the return type here: https://github.com/0no-co/wonka/blob/990c8da89b2d6e5be3d5f8ca2bd79b2a3a9fb00c/src/observable.ts#L79 To something like { unsubscribe(): void } please? I think that'd help out a lot to keep fromObservable flexible while making toObservable more strict ✌️

naporin0624 commented 1 year ago

ok! It took me a while, but I understand what you're saying and I'll fix it right away!