From f87d4db7402309ad14a8d902bc52d6bf125c3a3c Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 30 Sep 2020 15:01:38 +0100 Subject: [PATCH] Fix how getters are defined to work around broken minification --- packages/svelte-urql/src/operationStore.ts | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/svelte-urql/src/operationStore.ts b/packages/svelte-urql/src/operationStore.ts index 6466a4fd22..184acbfb30 100644 --- a/packages/svelte-urql/src/operationStore.ts +++ b/packages/svelte-urql/src/operationStore.ts @@ -48,17 +48,17 @@ export function operationStore( extensions: undefined, } as OperationStore; - const store = writable(state); + const svelteStore = writable(state); let _internalUpdate = false; - function set(value?: Partial) { + state.set = function set(value?: Partial) { if (!value) value = noop; _internalUpdate = true; if (process.env.NODE_ENV !== 'production') { if (!_storeUpdate.has(value!)) { for (const key in value) { - if (key !== 'query' && key !== 'variables') { + if (!(key in internal)) { throw new TypeError( 'It is not allowed to update result properties on an OperationStore.' ); @@ -80,32 +80,32 @@ export function operationStore( } _internalUpdate = false; - store.set(state); - } + svelteStore.set(state); + }; - function update(fn: Updater): void { - set(fn(state)); - } + state.update = function update(fn: Updater): void { + state.set(fn(state)); + }; - state.set = set; - state.update = update; - state.subscribe = store.subscribe; + state.subscribe = function subscribe(run, invalidate) { + return svelteStore.subscribe(run, invalidate); + }; - for (const prop in internal) { + Object.keys(internal).forEach(prop => { Object.defineProperty(state, prop, { configurable: false, get: () => internal[prop], set(value) { internal[prop] = value; - if (!_internalUpdate) store.set(state); + if (!_internalUpdate) svelteStore.set(state); }, }); - } + }); if (process.env.NODE_ENV !== 'production') { const result = { ...state }; - for (const prop in state) { + Object.keys(state).forEach(prop => { Object.defineProperty(result, prop, { configurable: false, get() { @@ -117,18 +117,18 @@ export function operationStore( ); }, }); - } + }); - for (const prop in internal) { + Object.keys(internal).forEach(prop => { Object.defineProperty(result, prop, { configurable: false, get: () => internal[prop], set(value) { internal[prop] = value; - if (!_internalUpdate) store.set(state); + if (!_internalUpdate) svelteStore.set(state); }, }); - } + }); return result; }