-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] For each reducer, generate
on_{reducer}
and once_{on_reducer}
Prior to this commit, to register an on-reducer callback for a reducer `set_name`, a client author would write `SetNameArgs::on_reducer(...)`, with their callback accepting a reference to a `SetNameArgs` which contained the reducer arguments. Now, in addition to that interface, we generate a function `on_set_name`, which accepts a callback that takes the arguments unpacked, rather than as a struct. That is, for the quickstart's `set_name` reducer, we generate: ```rust pub fn on_set_name( mut __callback: impl FnMut(&Identity, Status, &String) + Send + 'static, ) -> ReducerCallbackId<SetNameArgs> { SetNameArgs::on_reducer(move |__identity, __status, __args| { let SetNameArgs { name } = __args; __callback(__identity, __status, name); }) } ``` Note the use of double-underscored variable names to avoid name collisions, since we can't `gensym` a unique name. We also generate `once_on_set_name`, which is like `on_set_name`, but takes a `FnOnce` instead of a `FnMut`.
- Loading branch information
Showing
1 changed file
with
114 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters