-
Notifications
You must be signed in to change notification settings - Fork 152
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
feature: add save
hook to atoms
#399
Labels
Comments
bantic
added a commit
that referenced
this issue
Aug 25, 2016
Save hook is on the atom's `env` and accepts arguments: `(value, payload)`. Calling the save hook rerenders the atom. Example: ``` let atom = { name: 'my-atom', type: 'dom', render({env, value, payload}) { let el = document.createElement('button'); let clicks = payload.clicks || 0; el.appendChild(document.createTextNode('Clicks: ' + clicks)); el.onclick = () => { payload.clicks = payload.clicks || 0; payload.clicks++; env.save(value, payload); }; return el; } }; ``` Also: improve postAbstract buildFromText to accept data for an atom, i.e. "abc@(...jsondata...)", e.g.: ``` buildFromText('abc@("name": "my-atom", "value": "bob", "payload": {"foo": "bar"})def'); // -> "abc" + atom with name "my-atom", value "bob", payload {foo: 'bar'} + "def" ``` Fixes #399
bantic
added a commit
that referenced
this issue
Aug 25, 2016
Save hook is on the atom's `env` and accepts arguments: `(value, payload)`. Calling the save hook rerenders the atom. Example: ``` let atom = { name: 'my-atom', type: 'dom', render({env, value, payload}) { let el = document.createElement('button'); let clicks = payload.clicks || 0; el.appendChild(document.createTextNode('Clicks: ' + clicks)); el.onclick = () => { payload.clicks = payload.clicks || 0; payload.clicks++; env.save(value, payload); }; return el; } }; ``` Also: improve postAbstract buildFromText to accept data for an atom, i.e. "abc@(...jsondata...)", e.g.: ``` buildFromText('abc@("name": "my-atom", "value": "bob", "payload": {"foo": "bar"})def'); // -> "abc" + atom with name "my-atom", value "bob", payload {foo: 'bar'} + "def" ``` Fixes #399
bantic
added a commit
that referenced
this issue
Aug 25, 2016
Save hook is on the atom's `env` and accepts arguments: `(value, payload)`. Calling the save hook rerenders the atom. Example: ``` let atom = { name: 'my-atom', type: 'dom', render({env, value, payload}) { let el = document.createElement('button'); let clicks = payload.clicks || 0; el.appendChild(document.createTextNode('Clicks: ' + clicks)); el.onclick = () => { payload.clicks = payload.clicks || 0; payload.clicks++; env.save(value, payload); }; return el; } }; ``` Also: improve postAbstract buildFromText to accept data for an atom, i.e. "abc@(...jsondata...)", e.g.: ``` buildFromText('abc@("name": "my-atom", "value": "bob", "payload": {"foo": "bar"})def'); // -> "abc" + atom with name "my-atom", value "bob", payload {foo: 'bar'} + "def" ``` Fixes #399
released in v0.10.8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As requested in gitter by @t4t5, atoms should have a
save
hook to allow programmatically updating their value and/or payload.The text was updated successfully, but these errors were encountered: