@raythurnevoid/svelte-context-enhanced
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,1 +0,2 @@ | ||
export declare function createContext<T>(): readonly [(context: T) => T, () => T]; | ||
import type { ContextKey } from "./svelte-typed-context.js"; | ||
export declare function createContext<T>(key: ContextKey<T>): readonly [(context: T) => T, () => T]; |
import { getContext, setContext } from "./svelte-typed-context.js"; | ||
export function createContext() { | ||
const key = {}; | ||
export function createContext(key) { | ||
function setContextValue(context) { | ||
@@ -5,0 +4,0 @@ setContext(key, context); |
@@ -1,1 +0,2 @@ | ||
export declare function createContext<T>(): readonly [(context: T) => T, () => T]; | ||
import type { ContextKey } from "./svelte-typed-context.js"; | ||
export declare function createContext<T>(key: ContextKey<T>): readonly [(context: T) => T, () => T]; |
@@ -5,4 +5,3 @@ "use strict"; | ||
const svelte_typed_context_js_1 = require("./svelte-typed-context.js"); | ||
function createContext() { | ||
const key = {}; | ||
function createContext(key) { | ||
function setContextValue(context) { | ||
@@ -9,0 +8,0 @@ (0, svelte_typed_context_js_1.setContext)(key, context); |
@@ -1,4 +0,6 @@ | ||
import { readable } from "svelte/store"; | ||
import { readable, derived } from "svelte/store"; | ||
import type { Writable, Readable, StartStopNotifier } from "svelte/store"; | ||
export declare function createContextWritableStore<T>(): readonly [(value?: T, start?: StartStopNotifier<T>) => Writable<T>, () => Writable<T>]; | ||
export declare function createContextStore<T>(): readonly [typeof readable, () => Readable<T>]; | ||
import type { ContextKey } from "./svelte-typed-context.js"; | ||
export declare function createContextWritableStore<T>(key: ContextKey<Writable<T>>): readonly [(value?: T, start?: StartStopNotifier<T>) => Writable<T>, () => Writable<T>]; | ||
export declare function createContextDerivedStore<T>(key: ContextKey<Readable<T>>): readonly [typeof derived, () => Readable<T>]; | ||
export declare function createContextStore<T>(key: ContextKey<Readable<T>>): readonly [typeof readable, () => Readable<T>]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createContextStore = exports.createContextWritableStore = void 0; | ||
exports.createContextStore = exports.createContextDerivedStore = exports.createContextWritableStore = void 0; | ||
const store_1 = require("svelte/store"); | ||
const svelte_typed_context_js_1 = require("./svelte-typed-context.js"); | ||
function createContextWritableStore() { | ||
const key = {}; | ||
function createContextWritableStore(key) { | ||
function setContextValue(value, start) { | ||
@@ -19,4 +18,17 @@ const context$ = (0, store_1.writable)(value, start); | ||
exports.createContextWritableStore = createContextWritableStore; | ||
function createContextStore() { | ||
const key = {}; | ||
function createContextDerivedStore(key) { | ||
const setContextValue = new Proxy(store_1.derived, { | ||
apply(target, _thisArg, args) { | ||
const context$ = target(...args); | ||
(0, svelte_typed_context_js_1.setContext)(key, context$); | ||
return context$; | ||
}, | ||
}); | ||
function getContextValue() { | ||
return (0, svelte_typed_context_js_1.getContext)(key); | ||
} | ||
return [setContextValue, getContextValue]; | ||
} | ||
exports.createContextDerivedStore = createContextDerivedStore; | ||
function createContextStore(key) { | ||
const setContextValue = new Proxy(store_1.readable, { | ||
@@ -23,0 +35,0 @@ apply(target, _thisArg, args) { |
{ | ||
"name": "@raythurnevoid/svelte-context-enhanced", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -41,4 +41,4 @@ "scripts": { | ||
"dependencies": { | ||
"svelte": "^3.46.2" | ||
"svelte": "^3.47.0" | ||
} | ||
} |
import { getContext, setContext } from "./svelte-typed-context.js"; | ||
import type { ContextKey } from "./svelte-typed-context.js"; | ||
export function createContext<T>() { | ||
const key: ContextKey<T> = {}; | ||
export function createContext<T>(key: ContextKey<T>) { | ||
function setContextValue(context: T): T { | ||
@@ -8,0 +6,0 @@ setContext(key, context); |
@@ -1,2 +0,2 @@ | ||
import { readable, writable } from "svelte/store"; | ||
import { readable, writable, derived } from "svelte/store"; | ||
import type { Writable, Readable, StartStopNotifier } from "svelte/store"; | ||
@@ -6,5 +6,3 @@ import { getContext, setContext } from "./svelte-typed-context.js"; | ||
export function createContextWritableStore<T>() { | ||
const key: ContextKey<Writable<T>> = {}; | ||
export function createContextWritableStore<T>(key: ContextKey<Writable<T>>) { | ||
function setContextValue(value?: T, start?: StartStopNotifier<T>) { | ||
@@ -23,5 +21,19 @@ const context$ = writable(value, start); | ||
export function createContextStore<T>() { | ||
const key: ContextKey<Readable<T>> = {}; | ||
export function createContextDerivedStore<T>(key: ContextKey<Readable<T>>) { | ||
const setContextValue = new Proxy(derived, { | ||
apply(target, _thisArg, args: Parameters<typeof derived>) { | ||
const context$ = target(...args); | ||
setContext(key, context$); | ||
return context$; | ||
}, | ||
}); | ||
function getContextValue(): Readable<T> { | ||
return getContext(key); | ||
} | ||
return [setContextValue, getContextValue] as const; | ||
} | ||
export function createContextStore<T>(key: ContextKey<Readable<T>>) { | ||
const setContextValue = new Proxy(readable, { | ||
@@ -28,0 +40,0 @@ apply(target, _thisArg, args: Parameters<typeof readable>) { |
@@ -1,4 +0,6 @@ | ||
import { readable } from "svelte/store"; | ||
import { readable, derived } from "svelte/store"; | ||
import type { Writable, Readable, StartStopNotifier } from "svelte/store"; | ||
export declare function createContextWritableStore<T>(): readonly [(value?: T, start?: StartStopNotifier<T>) => Writable<T>, () => Writable<T>]; | ||
export declare function createContextStore<T>(): readonly [typeof readable, () => Readable<T>]; | ||
import type { ContextKey } from "./svelte-typed-context.js"; | ||
export declare function createContextWritableStore<T>(key: ContextKey<Writable<T>>): readonly [(value?: T, start?: StartStopNotifier<T>) => Writable<T>, () => Writable<T>]; | ||
export declare function createContextDerivedStore<T>(key: ContextKey<Readable<T>>): readonly [typeof derived, () => Readable<T>]; | ||
export declare function createContextStore<T>(key: ContextKey<Readable<T>>): readonly [typeof readable, () => Readable<T>]; |
21
store.js
@@ -1,5 +0,4 @@ | ||
import { readable, writable } from "svelte/store"; | ||
import { readable, writable, derived } from "svelte/store"; | ||
import { getContext, setContext } from "./svelte-typed-context.js"; | ||
export function createContextWritableStore() { | ||
const key = {}; | ||
export function createContextWritableStore(key) { | ||
function setContextValue(value, start) { | ||
@@ -15,4 +14,16 @@ const context$ = writable(value, start); | ||
} | ||
export function createContextStore() { | ||
const key = {}; | ||
export function createContextDerivedStore(key) { | ||
const setContextValue = new Proxy(derived, { | ||
apply(target, _thisArg, args) { | ||
const context$ = target(...args); | ||
setContext(key, context$); | ||
return context$; | ||
}, | ||
}); | ||
function getContextValue() { | ||
return getContext(key); | ||
} | ||
return [setContextValue, getContextValue]; | ||
} | ||
export function createContextStore(key) { | ||
const setContextValue = new Proxy(readable, { | ||
@@ -19,0 +30,0 @@ apply(target, _thisArg, args) { |
12921
261
Updatedsvelte@^3.47.0