Skip to content

Commit

Permalink
add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Mar 18, 2024
1 parent 9788d30 commit 4a35839
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .changeset/nervous-goats-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"anywidget": patch
"@anywidget/types": patch
---

Add experimental reducer API for sending/await-ing custom messages

Introduces a unified API for dispatching messages from the front end, and
await-ing response from Python. This removes a lot of boilerplate required for
this kind of pattern previously. This API is experimental and opt-in, only if
`_experimental_anywidget_reducer` is implemented on the anywidget subclass.

```py
class Widget(anywidget.AnyWidget):
_esm = """
async function render({ model, el, experimental }) {
let [response, buffers] = await experimental.dispatch("ping");
// Handle the response
console.log(response) // pong
}
export default { render };
"""

def _experimental_anywidget_reducer(self, action, buffers):
assert action == "ping"
return "pong", []
```

0 comments on commit 4a35839

Please sign in to comment.