Skip to content

Commit fd2a81f

Browse files
committed
Merge branch 'main' of https://github.com/efflore/ui-element into main
2 parents b510b59 + 87c6fe9 commit fd2a81f

18 files changed

+947
-259
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ Version 0.8.1
1414

1515
To bind events on, pass states to, and execute effects on elements, UIElement offers a chainable API on `this.self`, `this.first(selector)` or `this.all(selector)` with a `map()` method - just like arrays.
1616

17-
For example, `this.self.map(on('click', 'clicked', () => true))` binds an event handler for `'click'` on the custom element itself, setting its `'clicked'` state to `true`. With `this.all('sub-component').map(pass(this, { color: 'color' }))` you pass the `'color'` state on `this` to every instance of `<sub-component>` in the DOM subtree.
17+
For example, `this.self.map(on('click', () => this.set('clicked', true))` binds an event handler for `'click'` on the custom element itself, setting its `'clicked'` state to `true`. With `this.all('sub-component').map(pass({ color: 'color' }))` you pass the `'color'` state on `this` to every instance of `<sub-component>` in the DOM subtree.
1818

19-
There are 6 pre-defined auto-effects that can be applied on elements with `this.[self|first(selector)|all(selector)].map()`:
19+
There are 7 pre-defined auto-effects that can be applied on elements with `this.[self|first(selector)|all(selector)].map()`:
2020

2121
- `setText(state)`: set text content of the target element to the value of state; expects a state of type string; will preserve comment nodes inside the element
2222
- `setProperty(key, state=key)`: set a property of the target element to the value of state; accepts a state of any type
2323
- `setAttribute(name, state=name)`: set or remove an attribute on the element to the value of state; expects a state of type string (set) or undefined (remove)
2424
- `toggleAttribute(name, state=name)`: toggles a boolean attribute on the element according to the value of state; expects a state of type boolean
2525
- `toggleClass(token, state=token)`: toggles a class on the element according to the value of state; expects a state of type boolean
2626
- `setStyle(prop, state=prop)`: set an inline style on the element to the value of state; expects a state of type string for the CSS property value
27+
- `dispatch(event, state=event)`: dispatch a custom event with the value of state as detail; accepts a state of any type
2728

2829
You can define custom effects with `effect()`, either in the `connectedCallback()` or in a mapped function on `this.[self|first(selector)|all(selector)]`. `UIElement` will automatically trigger these effects and bundle the fine-grained DOM updates.
2930

@@ -65,8 +66,8 @@ class MyCounter extends UIElement {
6566
}
6667

6768
connectedCallback() {
68-
this.first('.decrement').map(on('click', 'value', (_, v) => --v))
69-
this.first('.increment').map(on('click', 'value', (_, v) => ++v))
69+
this.first('.decrement').map(on('click', () => this.set('value', v => --v)))
70+
this.first('.increment').map(on('click', () => this.set('value', v => ++v)))
7071
this.first('span').map(setText('value'))
7172
}
7273
}

0 commit comments

Comments
 (0)