Commit Graph
42 Commits
Author SHA1 Message Date
Evan AlmloffandJonathan Kelley 58c41f8561 Stores: Externally tracked state and reactive collections (#4483)
* map signals mutably

* boxed signals

* remove mutable borrow type from boxed writable

* improve map mut example

* restore boxed_mut helper

* make boxed readable/writable types copy

* Move away from the ReadOnlySignal alias in examples

* automatically convert Write

* Fix some tests

* ReadSignal and WriteSignal

* move read only signal alias

* make maps copy

* store prototype

* implement derive macro

* Handle generics in the derive macro

* Make Selector boxable

* derive boxed conversion

* Get rid of store type

* Remove hardcoded type from derive macro

* selector -> store

* Refactor store implementation

* more vec methods

* todo mvc store example

* Implement Storable for HashMap

* fix write

* restore sorting logic in todomvc

* derive readable and writable

* improve todomvc store example

* Result store

* Option store

* collect dead subscribers

* fix clippy and formatting

* recognize some common foreign types automatically

* fix foreign stores in props

* slice and array selectors

* clean up store example

* writable is child owned

* box selector

* read and write to builtins

* re-use the proc macro in the derive macro

* Switch to a extension trait based approach

* switch to extension traits in the derive macro

* transposed method

* derive enums

* Expose Store::new

* remove stores from the prelude

* More consistent naming scheme for SelectorScope methods

* document hashmap methods

* document index extension

* document option ext

* document result ext

* document slice extension

* document the vec extension

* make more methods borrow the store mutably

* Move to impls to have higher priority over the builtin write extension traits

* fix deadlock

* finish stores documentation

* Document the store macro

* cleanup docs and organization

* finish derive docs

* fix typo

* fix clippy

* fix doc tests

* fix derive macro with generics

* fix clippy

* test and fix empty structs

* clean up todomvc store example

* default to a boxed store writer to make it easier to type when providing to the context api

* fix cargo doc

* fix clippy in store example

* relax generational box lifetime bounds

* relax bounds

* relax signal bounds

* fix compilation

* read store

* relax bounds on default store impls

* fix enum derive

* Convert to readsignal and writesignal automatically

* simplify type matching logic

* add write store

* unsized stores

* shrink the path vec type

* use more concrete types

* remove opaque types

* remove copy bounds

* use lens as generic name everywhere

* more consistent borrow semantics

* use a concrete type for the signal metadata and mention references in the map docs

* improve todomvc store docs

* document store derive macro internals

* refactor macro

* improve selector node documentation

* fix clippy

* add btreemap

* fix doc tests

* more option methods

* fix doc

* fix clippy

* add a bunch more result methods

* add a bunch of bounds to the iterators

* fix clippy

* remove option from subscribers

* add store macro to generate extension traits

* fix store example

* fix deadlock

* fix docs

* fix doc tests

* fix clippy

* add stores to public api

* add store macro, and then update todomvc_store example

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
2025-08-05 11:30:21 -07:00
Evan Almloff d8d11db403 Boxed and mapped signals preparing for stores (#4413)
This PR contains just the breaking changes required for the upcoming store implementation. It adds two new primitives:

Mutable mapped signals (without a different subscriber list). This lets you scope a writable value and pass it to a child component. It requires two closures to map the immutable and mutable references to the inner signal. With stores, these closures will be derived
Boxed readable and writable values (ReadSignal, and WriteSignal). Any readable or writable types can be converted to a read signal or write signal with the boxed method or built in types are automatically converted into the boxed variants when passing into props


* map signals mutably

* boxed signals

* remove mutable borrow type from boxed writable

* improve map mut example

* restore boxed_mut helper

* make boxed readable/writable types copy

* Move away from the ReadOnlySignal alias in examples

* automatically convert Write

* Fix some tests

* ReadSignal and WriteSignal

* move read only signal alias

* make maps copy

* store prototype

* implement derive macro

* Handle generics in the derive macro

* Make Selector boxable

* derive boxed conversion

* Get rid of store type

* Remove hardcoded type from derive macro

* selector -> store

* Refactor store implementation

* more vec methods

* todo mvc store example

* Implement Storable for HashMap

* fix write

* restore sorting logic in todomvc

* derive readable and writable

* improve todomvc store example

* Result store

* Option store

* collect dead subscribers

* fix clippy and formatting

* recognize some common foreign types automatically

* fix foreign stores in props

* slice and array selectors

* clean up store example

* remove stores

* writable is child owned

* fix typo

* fix clippy

* fix doc tests
2025-07-31 13:19:55 -07:00
Jonathan Kelley e42b71b1ba Fix #2612: adjust readable trait to allow try_peek (#2714)
* Fix #2612: adjust readable trait to allow try_peek

Our implementation for Readable was inconsistent.
We had a try_unchecked variant for read but not for peek.
This resolves that by making a breaking change to the
Readable interface.

* fix doctests too
2024-07-26 18:20:16 -05:00
Evan Almloff 58f7efafea Make EventHandler copy (#2112)
* implement Copy for EventHandler
* implement from closure for event handler and remove special on prefix
* fix props implementation of EventHandler
2024-03-19 19:48:53 -07:00
Evan Almloff 492f0329bf remove flume, implement lazier memos 2024-03-06 11:38:28 -06:00
Evan Almloff 8689509eb5 erase the original readable type 2024-02-07 11:19:39 -06:00
Evan Almloff c8937cb4df make mapped signal readable 2024-02-07 09:35:06 -06:00
Evan Almloff 8324f5290a rename rc to reactive context to avoid confusion with Rc 2024-02-05 07:24:31 -06:00
Evan Almloff f2e48f10e9 simplify the crm example a bit more 2024-01-23 18:46:24 -06:00
Evan Almloff fc6912d4c0 make GlobalMemo and GlobalSignal not copy or clone 2024-01-23 18:37:50 -06:00
Evan Almloff 84e76dbdce remove duplicate vec utils defined in the read_impls 2024-01-23 17:23:04 -06:00
Evan Almloff 94c0c2e5b9 remove some old manual implementations of helpers 2024-01-23 11:29:13 -06:00
Evan Almloff 7f93263357 add a bunch more utilities to the trait 2024-01-23 10:56:26 -06:00
Evan Almloff 51d7133ca5 add readable and writable traits for signal-like structs 2024-01-23 10:05:59 -06:00
Evan Almloff e01f10e25d remove mappable and mappablemut traits 2024-01-22 16:51:25 -06:00
Jonathan Kelley 06d9b575b7 rename use_selector to use_memo 2024-01-20 23:32:12 -08:00
Evan Almloff c859ed3b12 create global selectors 2024-01-19 15:26:28 -06:00
Evan Almloff bc914deeaa create Signal::global 2024-01-19 13:46:17 -06:00
Evan Almloff 701093ede5 Try to rerun all dirty scopes before polling any tasks to fix effect ordering 2024-01-17 08:17:30 -06:00
Evan Almloff f6fd20bb61 fix signals 2024-01-16 13:57:31 -06:00
Evan Almloff 611f0d3b5f Merge branch 'maybe-sync-signal' into breaking 2024-01-16 13:49:53 -06:00
Jonathan Kelley 8559984e9d and mut bound to mut methods on signals 2024-01-15 23:24:59 -08:00
Evan Almloff 73b7f450a5 fix merge errors 2024-01-02 14:55:46 -06:00
Evan Almloff cddcd69200 Merge branch 'maybe-sync-signal' into map-signal 2024-01-02 14:17:01 -06:00
Evan Almloff b9d179c494 add as_mapped_ref 2024-01-01 10:44:21 -06:00
Evan Almloff 31489167f7 use map in the signal iterator 2023-12-23 13:52:23 -06:00
Evan Almloff 6b17d3db1e fix signals crate 2023-12-15 18:35:48 -06:00
Evan Almloff b3c5158524 fix tests 2023-11-07 13:15:19 -06:00
Evan Almloff 466005890d make effect system async to make signals send + sync 2023-11-06 18:47:51 -06:00
Evan Almloff 6eb4e7358b fix selector and signal unsync default 2023-11-06 14:46:26 -06:00
Evan Almloff ebbaacf073 fix read and write impls 2023-11-03 10:27:21 -05:00
Evan Almloff 0a8de1d40f clean up ref mapping with GATs 2023-11-02 19:35:53 -05:00
Evan Almloff 8a62e4a987 Merge branch 'master' into debug-signals 2023-10-31 13:55:20 -05:00
Evan Almloff 90e04edcdf make the signal runtime global 2023-10-30 14:25:31 -05:00
Evan Almloff 1126c1d329 make signal sync 2023-10-26 12:47:53 -05:00
Evan Almloff df85b25548 Add debug information to borrows and ownership in signals 2023-08-21 14:23:02 -05:00
Evan Almloff ed05abc196 document remaining methods in the signal crate 2023-08-07 18:00:17 -07:00
Evan Almloff cfd68bf7d9 document signals crate 2023-08-07 16:56:49 -07:00
Evan Almloff 646c161c7d create read only signal 2023-08-07 16:04:49 -07:00
Evan Almloff 190c65b15d fix memo and add tests 2023-08-07 14:31:03 -07:00
Evan Almloff 717c09c4a3 create tests for signals 2023-08-07 11:52:54 -07:00
Evan Almloff a6f611eccf fix subscriptions in events 2023-08-04 17:23:57 -07:00