1.0.15 • Published 2 years ago

@sveil/core v1.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

sveil (alpha version)

Sveil core (not for prod yet).

  • Allow to subscribe for svelte stores (with unsubscribeAll option)
  • Allow to get current value of store with $ sign (emulate svelte file behaiour)

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<number>;
	counterIncrement: SvelteStoreFn<unknown>;
	counterSet: SvelteStoreFn<number>;
}

// Add properties in type
export interface ComponentService extends SubscribitionsBase<State> {}

// Add properties in runtime
export class ComponentService extends Subscribitions {
	constructor(state: State) {
		super(state);
		// after 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);
	}
}
1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago