26 points | by bosmarcel an hour ago
8 comments
Proposed variant optimised for human readaiblity...
```js import mador from "mador"; const [read, write] = mador({ count: 1 }); read(".counter", ctx => ctx.el.textContent = ctx.count); write(".increment", "click", ctx => ctx.count++); write(ctx => ctx.count = 0); ```
## Read
Dependencies are detected automatically when the read function is run during initiation.
```js read(".counter", ctx => ctx.el.textContent = `Count: ${ctx.count}`); ```
## Write
Immediate:
```js write(ctx => ctx.count++); ```
Event-triggered:
```js write(".increment", "click", ctx => ctx.count++); ```
Event writes expose `ctx.el` and `ctx.event`.
Are reactive updates based on deep equality or reference equality?
It is based on ref. equality, so assignment through '=' will trigger an "effect".
Clean launch, good luck!
Thanx a lot!
Great work!
Thanks, I really appreciate it! Hope others will feel the same. The frontend community needs and deserves simple tools:)
This makes me think of a version of that comic where in the last pane, you get thrown out the window for suggesting such a sensible thing.
Proposed variant optimised for human readaiblity...
```js import mador from "mador"; const [read, write] = mador({ count: 1 }); read(".counter", ctx => ctx.el.textContent = ctx.count); write(".increment", "click", ctx => ctx.count++); write(ctx => ctx.count = 0); ```
## Read
Dependencies are detected automatically when the read function is run during initiation.
```js read(".counter", ctx => ctx.el.textContent = `Count: ${ctx.count}`); ```
## Write
Immediate:
```js write(ctx => ctx.count++); ```
Event-triggered:
```js write(".increment", "click", ctx => ctx.count++); ```
Event writes expose `ctx.el` and `ctx.event`.
Are reactive updates based on deep equality or reference equality?
It is based on ref. equality, so assignment through '=' will trigger an "effect".
Clean launch, good luck!
Thanx a lot!
Great work!
Thanks, I really appreciate it! Hope others will feel the same. The frontend community needs and deserves simple tools:)
This makes me think of a version of that comic where in the last pane, you get thrown out the window for suggesting such a sensible thing.