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

Support conditionals in event handlers #297

Open
alexnm opened this issue Jul 2, 2019 · 0 comments
Open

Support conditionals in event handlers #297

alexnm opened this issue Jul 2, 2019 · 0 comments
Labels
proposal Something up for debate

Comments

@alexnm
Copy link
Contributor

alexnm commented Jul 2, 2019

Context

Event handlers are still an experimental feature in the UIDL, but currently it supports stateChange and propCall as two different statements.

"click": [
  {
    "type": "stateChange",
    "modifies": "isExpanded",
    "newState": "$toggle"
  }
]

NOTE: $toggle is a special string we're looking for and abstracts the expression: state.key = !state.key it could be deprecated if we implement #295.

"click": [
  {
    "type": "propCall",
    "calls": "onClose",
    "args": []
  }
]

Problem

It would be a nice addition to be able to express a condition.

Consider this scenario: You want to change the a state key when a certain prop is being set.
Example: increment stateValue when props.isActive is true

handleClick() {
  if (this.props.isActive) {
    this.stateValue ++
  }
}

Solution

Another type of statement in the event handler:

"click": [
  {
    "type": "condition",
    "when": <conditional expression>,
    "then": [
       <statements>
     ]
  }
]

It can even support an else or a switch like statement later.

@alexnm alexnm added the proposal Something up for debate label Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Something up for debate
Projects
None yet
Development

No branches or pull requests

1 participant