Skip to content

fix: add typings for event stream and fix bugs that surfaced #5290

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

Merged
merged 3 commits into from
Aug 29, 2019

Conversation

domoritz
Copy link
Member

@domoritz domoritz commented Aug 13, 2019

Fixes #5289

@domoritz domoritz requested a review from arvind August 13, 2019 18:24
@domoritz domoritz force-pushed the dom/events-stream-typings branch from 00c4626 to 3cf59c5 Compare August 13, 2019 19:04
@domoritz domoritz changed the title Start fixes for event stream @domoritz fix: add typings for event stream and fix bugs that are surfaced Aug 13, 2019
@domoritz domoritz marked this pull request as ready for review August 13, 2019 19:04
@domoritz domoritz changed the title @domoritz fix: add typings for event stream and fix bugs that are surfaced fix: add typings for event stream and fix bugs that are surfaced Aug 13, 2019
@domoritz domoritz force-pushed the dom/events-stream-typings branch from 3cf59c5 to acce897 Compare August 13, 2019 19:19
if (filters.indexOf(filterExpr) < 0) {
filters.push(filterExpr);
}
return on;
Copy link
Member Author

@domoritz domoritz Aug 13, 2019

Choose a reason for hiding this comment

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

I had to add this to make the typings correct. Does JavaScript magically return the first argument here or does reduce have some other magic behavior?

Copy link
Member

Choose a reason for hiding this comment

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

No, nothing magic. Just a (somewhat lazy) re-appropriation of a reduce when a forEach would suffice (reusing the method to be reduce duplication of error checks for evt.between).

@@ -13,7 +13,7 @@ const clear: TransformCompiler = {

parse: (model, selDef, selCmpt) => {
if (selDef.clear) {
selCmpt.clear = parseSelector(selDef.clear, 'scope');
selCmpt.clear = isString(selDef.clear) ? parseSelector(selDef.clear, 'scope') : selDef.clear;
Copy link
Member Author

Choose a reason for hiding this comment

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

The check for string was missing here.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch! Thanks!

events(selCmpt, (_: OnEvent[], evt: EventStream) => {
const filters = evt.between[0].filter || (evt.between[0].filter = []);
events(selCmpt, (on: OnEvent[], evt: Stream) => {
const filters = array(evt.between[0].filter || (evt.between[0].filter = []));
Copy link
Member Author

Choose a reason for hiding this comment

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

We previously assumed that filter is an array. Was this assumption correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, once filters have been parsed by vega-event-selector, this property will always be an array.

@domoritz domoritz force-pushed the dom/events-stream-typings branch from acce897 to 63f3f1e Compare August 13, 2019 19:25
@domoritz domoritz changed the title fix: add typings for event stream and fix bugs that are surfaced fix: add typings for event stream and fix bugs that surfaced Aug 13, 2019
@domoritz domoritz force-pushed the dom/events-stream-typings branch from 63f3f1e to 423811c Compare August 13, 2019 19:50
@domoritz
Copy link
Member Author

Blocked by vega/ts-json-schema-generator#192

@domoritz
Copy link
Member Author

Instead of blocking on vega/ts-json-schema-generator#192, I sent vega/vega#1926.

@domoritz domoritz force-pushed the dom/events-stream-typings branch from d2e8c5b to ccd8209 Compare August 28, 2019 21:49
Copy link
Member

@arvind arvind left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @domoritz!

events(selCmpt, (_: OnEvent[], evt: EventStream) => {
const filters = evt.between[0].filter || (evt.between[0].filter = []);
events(selCmpt, (on: OnEvent[], evt: Stream) => {
const filters = array(evt.between[0].filter || (evt.between[0].filter = []));
Copy link
Member

Choose a reason for hiding this comment

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

Yes, once filters have been parsed by vega-event-selector, this property will always be an array.

if (filters.indexOf(filterExpr) < 0) {
filters.push(filterExpr);
}
return on;
Copy link
Member

Choose a reason for hiding this comment

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

No, nothing magic. Just a (somewhat lazy) re-appropriation of a reduce when a forEach would suffice (reusing the method to be reduce duplication of error checks for evt.between).

@@ -13,7 +13,7 @@ const clear: TransformCompiler = {

parse: (model, selDef, selCmpt) => {
if (selDef.clear) {
selCmpt.clear = parseSelector(selDef.clear, 'scope');
selCmpt.clear = isString(selDef.clear) ? parseSelector(selDef.clear, 'scope') : selDef.clear;
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch! Thanks!

@arvind arvind merged commit 4d75b7b into master Aug 29, 2019
@arvind arvind deleted the dom/events-stream-typings branch August 29, 2019 00:36
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.

Add types for selection's on
2 participants