-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from gagan-suie/main
Feat: added svelte stores
- Loading branch information
Showing
3 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { derived, writable, type Writable } from "svelte/store" | ||
|
||
class ChannelStore { | ||
constructor( | ||
public firstname: Writable<string> = writable(''), | ||
public lastname: Writable<string> = writable(''), | ||
) { } | ||
|
||
get fullname() { | ||
// Use derived to access writable values and export as readonly | ||
return derived( | ||
[this.firstname, this.lastname], | ||
([$firstName, $lastName]) => { | ||
return $firstName + " " + $lastName | ||
} | ||
) | ||
} | ||
} | ||
|
||
// Export a singleton | ||
export const myFormStore = new ChannelStore() | ||
|
||
// Allow for multiple stores (good for contexts) | ||
// export const createMyFormStore = () => new MyFormStore(); |
Empty file.