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

Refactor Event #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Refactor Event #36

wants to merge 4 commits into from

Conversation

glennsl
Copy link
Member

@glennsl glennsl commented Jan 27, 2020

Cleans it up and ensures it works on 4.09

@glennsl glennsl requested a review from bryphe January 27, 2020 08:11
let subscribe = (evt: t('a), f: cb('a)) => {
evt := List.append(evt^, [f]);
let unsubscribe = () => {
evt := List.filter(f => f !== f, evt^);
Copy link
Member Author

@glennsl glennsl Jan 27, 2020

Choose a reason for hiding this comment

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

This was a bug. It didn't remove one callback, but cleared the list entirely f !== f is always false. That's one argument against shadowing.

unsubscribe;
};

let dispatch = (evt: t('a), v: 'a) => List.iter(c => c(v), evt^);
let dispatch = (event, message) => List.iter(cb => cb(message), event^);
Copy link
Member Author

Choose a reason for hiding this comment

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

This module doesn't actually implement an "event" but rather an "event delegator". And the sloppy naming causes an issue here if you try to name the arguments properly, because what's passed in to be dispatched is what's usually considered the actual event. But since that name is taken I had to go with message here. Which isn't terrible, but also not all that accurate.

@@ -31,7 +31,7 @@ describe("ChildProcess", ({describe, _}) => {
let proc = ChildProcess.spawn("node", [|"-e", script|]);

let data = ref("");
let _event =
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just plain wrong, and is another good reason why you should add proper type annotations to ignored values, as a sanity check for yourself. That is what a static type system is for, after all.

@glennsl
Copy link
Member Author

glennsl commented Jan 27, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@glennsl
Copy link
Member Author

glennsl commented Jan 27, 2020

Mac CI seems broken :/

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.

1 participant