https://github.com/sveiljs/sveil
Sveil core (svelte additional features)
https://github.com/sveiljs/sveil
library state-management stores svelte typescript utils
Last synced: about 2 months ago
JSON representation
Sveil core (svelte additional features)
- Host: GitHub
- URL: https://github.com/sveiljs/sveil
- Owner: sveiljs
- License: mit
- Created: 2023-08-19T11:28:34.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-02T20:05:45.000Z (over 2 years ago)
- Last Synced: 2025-10-25T13:44:37.270Z (8 months ago)
- Topics: library, state-management, stores, svelte, typescript, utils
- Language: TypeScript
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sveil (alpha version)
Sveil core.
- Allow to subscribe for svelte stores (with unsubscribeAll option)
- Allow to get current value of store with $ sign (emulate svelte store auto subscription behaiour)
## Instalation
```
npm i @sveil/core
```
## Basic example
```
/* eslint-disable @typescript-eslint/no-empty-interface */
import { type SubscribitionsBase, Subscribitions } from '@sveil/core';
import type { SvelteComponentState, SvelteStore, SvelteStoreFn } from '@sveil/core';
export interface State extends SvelteComponentState {
counter: SvelteStore;
counterIncrement: SvelteStoreFn;
counterSet: SvelteStoreFn;
}
// Add properties in type
export interface ComponentService extends SubscribitionsBase {}
// Add properties in runtime
export class ComponentService extends Subscribitions {
constructor(state: State) {
super(state);
// after call super - value of counter should be accessable in class with this.$counter
// in component you just need to call this.unsubscribeAll() in onDestroy
this.addSubscription(this.addSubscriptionLog()); //subscription option 1
this.subscribeStore(this.counter, this.subscribeStoreLog); //subscription option 2
}
logCounter() {
console.log('this.$counter', this.$counter); //current value of counter store
}
addSubscriptionLog() {
return this.counter.subscribe((n) => {
console.log('addSubscription callback', n);
});
}
subscribeStoreLog(n: number) {
console.log('subscribeStore callback', n);
}
}
```