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

Add view function #109

Merged
merged 3 commits into from
Aug 14, 2019
Merged

Add view function #109

merged 3 commits into from
Aug 14, 2019

Conversation

paldepind
Copy link
Member

This PR is an attempt at addressing a problem pointed out by @deklanw in #107.

The issue is that the TodoMVC example contains a filterItem function for creating a button in a list. Since this list item should tell its parent when it's being clicked it calls output on the a element in it. However, to prevent the outputs from all the constructed filterItems from colliding the function takes a string and uses that string to change the property name of the outputted stream.

This causes two problems:

  • It doesn't type check.
  • When looking at the code in todoFooterView it is not apparent that filterItem provides any output since output is not called on its result. In a sense the output selected in todoFooterView "bubbles" two function levels up. This makes it hard to figure out where the output is actually coming from.

This PR fixes the problem by adding a view function. The idea is that view is like modelView without a model. Functions like filterItem should be considered custom components, but, since they don't have a model they should use view instead of modelView.

The only thing view does is that it turns a Component<O, any> into a Component<{}, O>. In other words, it unselects output by turning selected output into available output. Thus, by wrapping a component in view the selected output in that component doesn't "bubble" further up unless the parent makes it selected again by calling output.

I've adapted the TodoMVC example to use the view function.

I also propose that we consider it bad practice for a function to return a component which has already selected output. A function should always return a component with no selected output (just like modelView does) such that it becomes the callers job to select output and to prevent that output "bubbles" several layers up which makes it hard to track where things come from.

I would love to hear your opinion on this @deklanw.

Copy link
Member

@limemloh limemloh left a comment

Choose a reason for hiding this comment

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

LGTM (Let's Get This Merged)

selectAll: o.click.mapTo("all")
})),
filterItem("Active", selectedClass).output((o) => ({
selectActive: o.click.mapTo("all")
Copy link
Contributor

Choose a reason for hiding this comment

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

should be active ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nicely spotted 👍

@deklanw
Copy link
Contributor

deklanw commented Aug 13, 2019

@paldepind

Seems good to me. Although, it's another thing to think about. Made an issue for related thoughts I've been having #110

@paldepind paldepind merged commit ad91580 into master Aug 14, 2019
@paldepind paldepind deleted the add-view-function branch August 14, 2019 06:26
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.

3 participants