= TypeVar("T")
T = TypeVar("covT", covariant=True)
covT = Callable[[T], None] # a callback
Subscriber = Callable[[], None] # a callback to be used upon termination of the subscription
Unsubscriber = Callable[[T], T]
Updater = Callable[[Subscriber], Union[Unsubscriber, None]]
Notifier
class StoreProtocol(Protocol, Generic[covT]):
''' The Svelte Store ~~contract~~ protocol. '''
def subscribe(self, subscriber: Subscriber[T]) -> Unsubscriber: ...
= StoreProtocol[T]
Readable: TypeAlias
class Writable(Readable[T]):
''' Writable protocol'''
def set(self, value: T) -> None: ...
def update(self, updater: Updater[T]) -> None: ...
stores
The Svelte Store contract
A store must contain a
.subscribe
method, which must accept as its argument asubscription function
(aka Subscriber or Callback). Thissubscription function
must be immediately and synchronously called with the store’s current value upon callingsubscribe
. All of a store’s active subscription functions must later be synchronously called whenever the store’s value changes.The
.subscribe
method must return anunsubscribe function
(aka Unsubscriber). Calling anunsubscribe function
muststop
its subscription, and its correspondingsubscription function
must not be called again by the store.A store may optionally contain a
.set
method, which must accept as its argument a new value for the store, and which synchronously calls all of the store’s active subscription functions. Such a store is called a writable store.
For interoperability with RxJS Observables, the .subscribe method is also allowed to return an object with an .unsubscribe method, rather than return the unsubscription function directly. Note however that unless .subscribe synchronously calls the subscription (which is not required by the Observable spec), Svelte will see the value of the store as undefined until it does.
Types Definition
Writable
Writable (*args, **kwargs)
Writable protocol
StoreProtocol
StoreProtocol (*args, **kwargs)
The Svelte Store contract protocol.
Implementation
Writable Store
Store
Store (initial_value:Any=None, start:Notifier=<function noop>)
A Writable Store.
Type | Default | Details | |
---|---|---|---|
initial_value | Any | None | initial value of the store |
start | Notifier | noop | A Notifier (Optional) |
Returns | None |
Writable Factory
writable
writable (value:~T=None, start:Callable[[Callable[[~T],NoneType]],Optiona l[Callable[[],NoneType]]]=<function noop>)
Creates a new Writable Store (A Writable factory).
Type | Default | Details | |
---|---|---|---|
value | T | None | initial value of the store |
start | Notifier | noop | Optional Notifier, a function called when the first subscriber is added |
Returns | Writable[T] | Writable Store |
Readable Store
ReadableStore
ReadableStore (initial_value:T, start:Notifier)
A Readable Store.
Type | Details | |
---|---|---|
initial_value | T | initial value of the store |
start | Notifier | function called when the first subscriber is added |
Returns | None |
Readable Factory
readable
readable (value:~T, start:Callable[[Callable[[~T],NoneType]],Optional[Cal lable[[],NoneType]]])
Creates a new Readable Store (A Readable factory).
Type | Details | |
---|---|---|
value | T | initial value of the store |
start | Notifier | function called when the first subscriber is added |
Returns | Readable[T] | Readable Store |
Derived Store
DerivedStore
DerivedStore (s:Union[Store,list[Store]], *functions:Callable)
A Derived Store.
Type | Details | |
---|---|---|
s | Union[Store, listStore] | source store(s) |
functions | Callable | |
Returns | None | a callback that takes the source store(s) values and returns the derived value |
Derived Factory
derived
Creates a new Derived Store (A Derived factory).
= derived(a, lambda a: f"{a}")
d d
r<0> $str: 'fonzie'
Pipe Operator
show_doc
show_doc (sym, renderer=None, name:Optional[str]=None, title_level:int=3)
Show signature and docstring for sym
Type | Default | Details | |
---|---|---|---|
sym | Symbol to document | ||
renderer | NoneType | None | Optional renderer (defaults to markdown) |
name | str | None | None | Optionally override displayed name of sym |
title_level | int | 3 | Heading level to use for symbol name |