-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Budibase/budibase into dependabot…
…/npm_and_yarn/examples/nextjs-api-sales/next-14.2.15
- Loading branch information
Showing
24 changed files
with
303 additions
and
186 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,44 +1,41 @@ | ||
import { writable, Writable } from "svelte/store" | ||
import { writable, Writable, Readable } from "svelte/store" | ||
|
||
interface BudiStoreOpts { | ||
debug?: boolean | ||
} | ||
|
||
export default class BudiStore<T> implements Writable<T> { | ||
export class BudiStore<T> { | ||
store: Writable<T> | ||
subscribe: Writable<T>["subscribe"] | ||
update: Writable<T>["update"] | ||
set: Writable<T>["set"] | ||
|
||
constructor(init: T, opts?: BudiStoreOpts) { | ||
const store = writable<T>(init) | ||
|
||
/** | ||
* Internal Svelte store | ||
*/ | ||
this.store = store | ||
|
||
/** | ||
* Exposes the svelte subscribe fn to allow $ notation access | ||
* @example | ||
* $navigation.selectedScreenId | ||
*/ | ||
this.store = writable<T>(init) | ||
this.subscribe = this.store.subscribe | ||
|
||
/** | ||
* Exposes the svelte update fn. | ||
* *Store modification should be kept to a minimum | ||
*/ | ||
this.update = this.store.update | ||
this.set = this.store.set | ||
|
||
/** | ||
* Optional debug mode to output the store updates to console | ||
*/ | ||
// Optional debug mode to output the store updates to console | ||
if (opts?.debug) { | ||
this.subscribe(state => { | ||
console.warn(`${this.constructor.name}`, state) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export class DerivedBudiStore<T, DerivedT extends T> extends BudiStore<T> { | ||
derivedStore: Readable<DerivedT> | ||
subscribe: Readable<DerivedT>["subscribe"] | ||
|
||
constructor( | ||
init: T, | ||
makeDerivedStore: (store: Writable<T>) => Readable<DerivedT>, | ||
opts?: BudiStoreOpts | ||
) { | ||
super(init, opts) | ||
this.derivedStore = makeDerivedStore(this.store) | ||
this.subscribe = this.derivedStore.subscribe | ||
} | ||
} |
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
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
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
Oops, something went wrong.