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

Expressions in bindings #3

Open
thejohnfreeman opened this issue May 7, 2012 · 2 comments
Open

Expressions in bindings #3

thejohnfreeman opened this issue May 7, 2012 · 2 comments

Comments

@thejohnfreeman
Copy link
Member

We should make an effort to support expressions in bindings.

It is important to note before the below discussion that we cannot know the type of an option value---e.g., normal function vs variable vs other type---before running the binding monad. We can, with the help of a parser, know if it is a function expression vs an identifier vs something else, but that might not be enough: a plain identifier could name anything.

To support expressions, they could be wrapped in a computed variable:

var option = hd.computed(function () {
  return <expression>;
});

Consider each kind of expression:

  • constant: The method is only ever executed once. Event handlers are created but never needed and only used to initialize.
  • function expression: If the binding, e.g. click, expects an event handler and not a variable, then this creates a problem. The binder has to subscribe to changes on the variable with a response that detaches the old handler and attaches the new handler. Do we want to support a use case where function expressions change?
  • variable read: A new computed variable is constructed when the variable could be used directly.
  • method call on a member of the context: Is the method returning a constant or a variable?
  • other expression: Does the right thing. :/
@thejohnfreeman
Copy link
Member Author

Another case:

  • method of an object: Should result in a function with a bound context.

@thejohnfreeman
Copy link
Member Author

Revisiting the function expression / method expression cases:

  • function expression: nameOfFunction
    HotDrink should turn this into a function where this is the current context and the parameter is $this.
  • method expression: nameOfObject.nameOfMethod
    HotDrink should turn this into a function where this is the object named and the parameter is $this.

These functions might be subscribed to events, and as such will receive an event parameter. They should be sure to wrap the functions specified by the programmer so that the programmer's function gets called with $this.

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

No branches or pull requests

1 participant