Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watch is a stream #121

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

watch is a stream #121

wants to merge 7 commits into from

Conversation

mafintosh
Copy link
Contributor

Some changes to the experimental watch api

  • watch now returns a stream, so there is parity with our other apis - same teardown etc etc
  • map is now more flexible, it takes both snaps as an arg and allows the user to map to whatever and is also async now
  • unmap exists so the user can specify teardown

index.js Show resolved Hide resolved
this.range = range
this.current = null
this.previous = null
this.map = opts.map || null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map and unmap are already set in the superclass. Would either handle completely there, or completely in the subclasses.

KeyWatchStream only seems to have map and no unmap, and no concept of _mapped either, so probably makessense to keep in subclass

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opened logic could live fully in the superclass btw, and the subclasses just need to overwrite _setup--now it lives in both (sueprclass still has this.opened)

this._differ = opts.differ || defaultDiffer
this._checkout = opts.checkout || (opts.eager ? 1 : 0)

this.opened = this._setup()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opening flow is a bit confusing compared with how we do it elsewhere, normally this.opened is a bool (in ready-resource). Not sure what the standard for streams is though

How about calling it this.opening and exposing an async ready() { return this.opening } method? That way the api is compat with ready resource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can it opened on other streams in the stack so named it this for consistency. also you shouldn’t really use this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case it makes sense to keep the stream naming. Do note that await watcher.opened is documented in the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, we should kill that. the stream already emits open when its open, so its mostly a stream concern anywho

})

if (!(await this._didRangeChange())) return null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: no need for the if (this.destroying) return null check here? (not sure if _didRangeChange can return true with the stream being destroyed before this is code is reached)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Will add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants