Closed wainwrightmark closed 1 year ago
Hi. I pattern I use quite often is a history store that enables undo/redo functionality for a particular store.
It's quite a common pattern and can be implemented generically so I wonder if it would be worth creating a macro to automatically generate it.
usage would look something like this
#[derive(Default, Clone, PartialEq, Eq, Debug)] #[store(history)] struct CounterStore { count: i32, } #[function_component] fn Controls() -> Html { let (state, dispatch) = use_store::<CounterStoreHistoryState>(); let on_undo_click = dispatch.apply_callback(|_| CounterStoreHistoryMessage::Undo); let on_redo_click = dispatch.apply_callback(|_| CounterStoreHistoryMessage::Redo); html!( <div> <button onclick={on_undo_click} disabled={undo_disabled}>{"Undo"}</button> <button onclick={on_redo_click} disabled={redo_disabled}>{"Redo"}</button> </div> ) }
The CounterStoreHistoryState and CounterStoreHistoryMessage structs are generated by the macro.
CounterStoreHistoryState
CounterStoreHistoryMessage
Happy to do a PR if you think this is a good idea - I've already written the code a couple of times, just need to write a macro to generate it.
Sure, I can see a place for this. Maybe add a crate to the workspace called yewdux-utils or something. That can be the home for this kind of stuff
Released!
Hi. I pattern I use quite often is a history store that enables undo/redo functionality for a particular store.
It's quite a common pattern and can be implemented generically so I wonder if it would be worth creating a macro to automatically generate it.
usage would look something like this
The
CounterStoreHistoryState
andCounterStoreHistoryMessage
structs are generated by the macro.Happy to do a PR if you think this is a good idea - I've already written the code a couple of times, just need to write a macro to generate it.