Closed evdokimovs closed 3 years ago
Part of #27, #47
Required for #164
For #164 we need to implement macro which will generate method for spawning listeners for observable field changes.
Also in this PR Component structure will be added, because #[watchable] macro works only with this concrete struct.
Component
#[watchable]
Add macro which will generate from code like this:
struct FooState { muted: ObservableCell<bool>, } struct FooCtx; type FooComponent = Component<FooState, FooCtx>; #[watchers] impl FooComponent { #[watch(self.state().muted.subscribe())] async fn muted_change_watcher( ctx: Rc<FooCtx>, state: Rc<FooState>, new_muted_val: bool ) -> Result<(), ()> { Ok(()) } }
code like this:
impl FooComponent { fn spawn(&self) { self.spawn_watcher( self.state().muted.subscribe(), Self::muted_change_watcher, ); } async fn muted_change_watcher( ctx: Rc<FooCtx>, state: Rc<FooState>, new_muted_val: bool ) -> Result<(), ()> { Ok(()) } }
Draft:
k::
Add #[watchable] macro to 'medea-macro' crate (#169, #27, #47) - impl reactivity Component structure and its helper abstractions in 'medea-jason' crate
Part of #27, #47
Required for #164
Synopsis
For #164 we need to implement macro which will generate method for spawning listeners for observable field changes.
Also in this PR
Component
structure will be added, because#[watchable]
macro works only with this concrete struct.Solution
Add macro which will generate from code like this:
code like this:
Checklist
Draft:
prefixk::
labels appliedDraft:
prefix is removed