value-enhancer
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -1,2 +0,2 @@ | ||
"use strict";var e=Object.defineProperty,s=("undefined"!=typeof require&&require,(s,r,t)=>(((s,r,t)=>{r in s?e(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t})(s,"symbol"!=typeof r?r+"":r,t),t));Object.defineProperty(exports,"__esModule",{value:!0}),exports[Symbol.toStringTag]="Module";class r{constructor(e,r){s(this,"_value"),s(this,"_beforeDestroys"),s(this,"_subscribers"),this._value=e,r&&(this.compare=r)}get value(){return this._value}setValue(e,s){if(!this.compare(e,this._value)){const r=this._value;this._value=e,this._subscribers&&this._subscribers.forEach((t=>t(e,r,s)))}}reaction(e){return this._subscribers||(this._subscribers=new Set),this._subscribers.add(e),()=>{this._subscribers&&this._subscribers.delete(e)}}subscribe(e,s){const r=this.reaction(e);return e(this._value,void 0,s),r}derive(e,s,t){const o=new r(e(this.value,void 0,t),s),i=this.reaction(((s,r,t)=>{o.setValue(e(s,r,t))}));return o.addBeforeDestroy(i),o}destroy(){this._beforeDestroys&&(this._beforeDestroys.forEach((e=>e())),this._beforeDestroys.clear()),this._subscribers&&this._subscribers.clear()}addBeforeDestroy(e){return this._beforeDestroys||(this._beforeDestroys=new Set),this._beforeDestroys.add(e),()=>{this._beforeDestroys&&this._beforeDestroys.delete(e)}}compare(e,s){return e===s}}function t(e,s,t,o){let i=e.map((e=>e.value));const a=new r(s(i,void 0,o),t);return e.forEach(((e,r)=>{const t=e.reaction(((e,t)=>{const o=i.slice();o[r]=e;const c=i;i=o,a.setValue(s(o,c,t),t)}));a.addBeforeDestroy(t)})),a}function o(e,s,r){var t;Object.defineProperties(e,{[s]:{get:()=>r.value},[`$${s}`]:{value:r},[`set${t=s,t[0].toUpperCase()+t.slice(1)}`]:{value:(e,s)=>r.setValue(e,s)}})}exports.Val=r,exports.combine=t,exports.createSideEffectBinder=function(e){const s=s=>{const r=e.addDisposer((()=>{s.destroy()}));return s.addBeforeDestroy((()=>{e.remove(r)})),s};return{bindSideEffect:s,combine:(e,r,o,i)=>s(t(e,r,o,i)),createVal:(e,t)=>s(new r(e,t))}},exports.enhanceVal=o,exports.withValueEnhancer=function(e,s){Object.keys(s).forEach((r=>{o(e,r,s[r])}))}; | ||
"use strict";var e=Object.defineProperty,s=("undefined"!=typeof require&&require,(s,r,t)=>(((s,r,t)=>{r in s?e(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t})(s,"symbol"!=typeof r?r+"":r,t),t));Object.defineProperty(exports,"__esModule",{value:!0}),exports[Symbol.toStringTag]="Module";class r{constructor(e,r){s(this,"_value"),s(this,"_beforeDestroys"),s(this,"_subscribers"),this._value=e,r&&(this.compare=r)}get value(){return this._value}setValue(e,s){if(!this.compare(e,this._value)){const r=this._value;this._value=e,this._subscribers&&this._subscribers.forEach((t=>t(e,r,s)))}}reaction(e){return this._subscribers||(this._subscribers=new Set),this._subscribers.add(e),()=>{this._subscribers&&this._subscribers.delete(e)}}subscribe(e,s){const r=this.reaction(e);return e(this._value,void 0,s),r}derive(e,s,t){const o=new r(e(this.value,void 0,t),s),i=this.reaction(((s,r,t)=>{o.setValue(e(s,r,t))}));return o.addBeforeDestroy(i),o}destroy(){this._beforeDestroys&&(this._beforeDestroys.forEach((e=>e())),this._beforeDestroys.clear()),this._subscribers&&this._subscribers.clear()}addBeforeDestroy(e){return this._beforeDestroys||(this._beforeDestroys=new Set),this._beforeDestroys.add(e),()=>{this._beforeDestroys&&this._beforeDestroys.delete(e)}}compare(e,s){return e===s}}function t(e,s,t,o){let i=e.map((e=>e.value));const a=new r(s(i,void 0,o),t);return e.forEach(((e,r)=>{const t=e.reaction(((e,t)=>{const o=i.slice();o[r]=e;const c=i;i=o,a.setValue(s(o,c,t),t)}));a.addBeforeDestroy(t)})),a}function o(e,s,r){var t;Object.defineProperties(e,{[s]:{get:()=>r.value},[`_${s}$`]:{value:r},[`set${t=s,t[0].toUpperCase()+t.slice(1)}`]:{value:(e,s)=>r.setValue(e,s)}})}exports.Val=r,exports.combine=t,exports.createSideEffectBinder=function(e){const s=s=>{const r=e.addDisposer((()=>{s.destroy()}));return s.addBeforeDestroy((()=>{e.remove(r)})),s};return{bindSideEffect:s,combine:(e,r,o,i)=>s(t(e,r,o,i)),createVal:(e,t)=>s(new r(e,t))}},exports.enhanceVal=o,exports.withValueEnhancer=function(e,s){Object.keys(s).forEach((r=>{o(e,r,s[r])}))}; | ||
//# sourceMappingURL=value-enhancer.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
var e=Object.defineProperty,s=("undefined"!=typeof require&&require,(s,r,t)=>(((s,r,t)=>{r in s?e(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t})(s,"symbol"!=typeof r?r+"":r,t),t));class r{constructor(e,r){s(this,"_value"),s(this,"_beforeDestroys"),s(this,"_subscribers"),this._value=e,r&&(this.compare=r)}get value(){return this._value}setValue(e,s){if(!this.compare(e,this._value)){const r=this._value;this._value=e,this._subscribers&&this._subscribers.forEach((t=>t(e,r,s)))}}reaction(e){return this._subscribers||(this._subscribers=new Set),this._subscribers.add(e),()=>{this._subscribers&&this._subscribers.delete(e)}}subscribe(e,s){const r=this.reaction(e);return e(this._value,void 0,s),r}derive(e,s,t){const i=new r(e(this.value,void 0,t),s),o=this.reaction(((s,r,t)=>{i.setValue(e(s,r,t))}));return i.addBeforeDestroy(o),i}destroy(){this._beforeDestroys&&(this._beforeDestroys.forEach((e=>e())),this._beforeDestroys.clear()),this._subscribers&&this._subscribers.clear()}addBeforeDestroy(e){return this._beforeDestroys||(this._beforeDestroys=new Set),this._beforeDestroys.add(e),()=>{this._beforeDestroys&&this._beforeDestroys.delete(e)}}compare(e,s){return e===s}}function t(e,s,t,i){let o=e.map((e=>e.value));const c=new r(s(o,void 0,i),t);return e.forEach(((e,r)=>{const t=e.reaction(((e,t)=>{const i=o.slice();i[r]=e;const a=o;o=i,c.setValue(s(i,a,t),t)}));c.addBeforeDestroy(t)})),c}function i(e,s){Object.keys(s).forEach((r=>{o(e,r,s[r])}))}function o(e,s,r){var t;Object.defineProperties(e,{[s]:{get:()=>r.value},[`$${s}`]:{value:r},[`set${t=s,t[0].toUpperCase()+t.slice(1)}`]:{value:(e,s)=>r.setValue(e,s)}})}function c(e){const s=s=>{const r=e.addDisposer((()=>{s.destroy()}));return s.addBeforeDestroy((()=>{e.remove(r)})),s};return{bindSideEffect:s,combine:(e,r,i,o)=>s(t(e,r,i,o)),createVal:(e,t)=>s(new r(e,t))}}export{r as Val,t as combine,c as createSideEffectBinder,o as enhanceVal,i as withValueEnhancer}; | ||
var e=Object.defineProperty,s=("undefined"!=typeof require&&require,(s,r,t)=>(((s,r,t)=>{r in s?e(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t})(s,"symbol"!=typeof r?r+"":r,t),t));class r{constructor(e,r){s(this,"_value"),s(this,"_beforeDestroys"),s(this,"_subscribers"),this._value=e,r&&(this.compare=r)}get value(){return this._value}setValue(e,s){if(!this.compare(e,this._value)){const r=this._value;this._value=e,this._subscribers&&this._subscribers.forEach((t=>t(e,r,s)))}}reaction(e){return this._subscribers||(this._subscribers=new Set),this._subscribers.add(e),()=>{this._subscribers&&this._subscribers.delete(e)}}subscribe(e,s){const r=this.reaction(e);return e(this._value,void 0,s),r}derive(e,s,t){const i=new r(e(this.value,void 0,t),s),o=this.reaction(((s,r,t)=>{i.setValue(e(s,r,t))}));return i.addBeforeDestroy(o),i}destroy(){this._beforeDestroys&&(this._beforeDestroys.forEach((e=>e())),this._beforeDestroys.clear()),this._subscribers&&this._subscribers.clear()}addBeforeDestroy(e){return this._beforeDestroys||(this._beforeDestroys=new Set),this._beforeDestroys.add(e),()=>{this._beforeDestroys&&this._beforeDestroys.delete(e)}}compare(e,s){return e===s}}function t(e,s,t,i){let o=e.map((e=>e.value));const c=new r(s(o,void 0,i),t);return e.forEach(((e,r)=>{const t=e.reaction(((e,t)=>{const i=o.slice();i[r]=e;const a=o;o=i,c.setValue(s(i,a,t),t)}));c.addBeforeDestroy(t)})),c}function i(e,s){Object.keys(s).forEach((r=>{o(e,r,s[r])}))}function o(e,s,r){var t;Object.defineProperties(e,{[s]:{get:()=>r.value},[`_${s}$`]:{value:r},[`set${t=s,t[0].toUpperCase()+t.slice(1)}`]:{value:(e,s)=>r.setValue(e,s)}})}function c(e){const s=s=>{const r=e.addDisposer((()=>{s.destroy()}));return s.addBeforeDestroy((()=>{e.remove(r)})),s};return{bindSideEffect:s,combine:(e,r,i,o)=>s(t(e,r,i,o)),createVal:(e,t)=>s(new r(e,t))}}export{r as Val,t as combine,c as createSideEffectBinder,o as enhanceVal,i as withValueEnhancer}; | ||
//# sourceMappingURL=value-enhancer.es.js.map |
@@ -5,3 +5,3 @@ import type { ExtractValMeta, ExtractValValue } from "./combine"; | ||
declare type ExtractValKeys<TInstance, TKey = keyof TInstance> = TKey extends Extract<keyof TInstance, string> ? TInstance[TKey] extends Val ? TKey : never : never; | ||
export declare type ValEnhancer<TVal, TKey extends string> = Readonly<Record<TKey, ExtractValValue<TVal>> & Record<`$${TKey}`, TVal> & Record<`set${Capitalize<TKey>}`, (value: ExtractValValue<TVal>, meta?: ExtractValMeta<TVal>) => void>>; | ||
export declare type ValEnhancer<TVal, TKey extends string> = Readonly<Record<TKey, ExtractValValue<TVal>> & Record<`_${TKey}$`, TVal> & Record<`set${Capitalize<TKey>}`, (value: ExtractValValue<TVal>, meta?: ExtractValMeta<TVal>) => void>>; | ||
export declare type ValEnhancerConfig = Record<string, Val>; | ||
@@ -8,0 +8,0 @@ declare type ToValUnion<TConfig, TKey = ExtractValKeys<TConfig>> = TKey extends ExtractValKeys<TConfig> ? ValEnhancer<TConfig[TKey], TKey> : never; |
{ | ||
"name": "value-enhancer", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A tiny library to enhance value with reactive wrapper.", |
@@ -23,3 +23,3 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
Record<TKey, ExtractValValue<TVal>> & | ||
Record<`$${TKey}`, TVal> & | ||
Record<`_${TKey}$`, TVal> & | ||
Record< | ||
@@ -64,3 +64,3 @@ `set${Capitalize<TKey>}`, | ||
}, | ||
[`$${key}`]: { | ||
[`_${key}$`]: { | ||
value: val, | ||
@@ -67,0 +67,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44248