feat: add effect cleanups, add docs (#2)

* docs: update readme

* feat: add cleanup function to effects

* refactor: move peek function to store module

* test: add nested atom check

* docs: add doc comments

* fix: `effect()` type

* refactor: remove divider comment
This commit is contained in:
richard 2024-06-02 01:25:00 -07:00 • committed by GitHub
parent 1a65a4a0de
commit 6a9c580bd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 805 additions and 76 deletions

View file

@ -4,13 +4,29 @@ type SyncPayload = types.SyncPayload
local patch = require(script.Parent.patch)
type ClientOptions = {
--[=[
The atoms to synchronize with the server.
]=]
atoms: { [string]: Atom<any> },
}
type ClientSyncer = {
--[=[
Applies a patch or initializes the state of the atoms with the given
payload from the server.
@param payload The patch or hydration payload to apply.
]=]
sync: (self: ClientSyncer, payload: SyncPayload) -> (),
}
--[=[
Creates a `ClientSyncer` object that receives patches from the server and
applies them to the local state.
@param options The atoms to synchronize with the server.
@return A `ClientSyncer` object.
]=]
local function client(options: ClientOptions): ClientSyncer
local atoms = options.atoms
local self = {} :: ClientSyncer