@cfcs/core
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -5,2 +5,3 @@ export declare function injectReactiveSubscribe(object: Record<string, any>): void; | ||
* @typedef | ||
* @memberof Reactive | ||
*/ | ||
@@ -7,0 +8,0 @@ export interface ReactiveSubscribe<State extends Record<string, any>> { |
@@ -11,6 +11,24 @@ import { ComputedObserver } from "./ComputedObserver"; | ||
}>; | ||
/** | ||
* @typedef | ||
* @memberof Reactive | ||
* @extends Reactive.ReactiveSubscribe | ||
*/ | ||
export declare type ReactiveObject<Object extends Record<string, any>> = ConvertValue<Object> & ReactiveSubscribe<PickObverser<Object>>; | ||
export declare function reactive<Object extends Record<string, any>>(setup: Readonly<Object> | (() => Readonly<Object>), all?: boolean): ReactiveObject<Object>; | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Only the values to which observer is applied are objects to which reactive is applied. | ||
*/ | ||
export declare function reactive<Object extends Record<string, any>>(setup: Readonly<Object> | (() => Readonly<Object>)): ReactiveObject<Object>; | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Makes all values into reactive objects. | ||
*/ | ||
export declare function reactiveAll<Object extends Record<string, any>>(setup: Readonly<Object> | (() => Readonly<Object>)): ReactiveObject<Object>; | ||
export declare function computed<Type>(computedCallback: () => Type): ComputedObserver<Type>; | ||
export declare function observe<Type>(defaultValue?: Type): Observer<Type>; | ||
export {}; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.13 | ||
version: 0.0.14 | ||
*/ | ||
@@ -357,3 +357,3 @@ 'use strict'; | ||
function reactive(setup, all) { | ||
function makeReactiveObject(setup, all) { | ||
var result = isFunction(setup) ? setup() : setup; | ||
@@ -367,5 +367,2 @@ var reactiveObject = {}; | ||
setObserver(reactiveObject, name, value); | ||
} else if (!all) { | ||
reactiveObject[name] = value; | ||
return; | ||
} else { | ||
@@ -380,2 +377,23 @@ setObserver(reactiveObject, name, observe(value)); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Only the values to which observer is applied are objects to which reactive is applied. | ||
*/ | ||
function reactive(setup) { | ||
return makeReactiveObject(setup); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Makes all values into reactive objects. | ||
*/ | ||
function reactiveAll(setup) { | ||
return makeReactiveObject(setup); | ||
} | ||
function computed(computedCallback) { | ||
@@ -551,2 +569,3 @@ return new ComputedObserver(computedCallback); | ||
exports.reactive = reactive; | ||
exports.reactiveAll = reactiveAll; | ||
exports.setObserver = setObserver; | ||
@@ -553,0 +572,0 @@ exports.withClassMethods = withClassMethods; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.13 | ||
version: 0.0.14 | ||
*/ | ||
@@ -355,3 +355,3 @@ import Component from '@egjs/component'; | ||
function reactive(setup, all) { | ||
function makeReactiveObject(setup, all) { | ||
var result = isFunction(setup) ? setup() : setup; | ||
@@ -365,5 +365,2 @@ var reactiveObject = {}; | ||
setObserver(reactiveObject, name, value); | ||
} else if (!all) { | ||
reactiveObject[name] = value; | ||
return; | ||
} else { | ||
@@ -378,2 +375,23 @@ setObserver(reactiveObject, name, observe(value)); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Only the values to which observer is applied are objects to which reactive is applied. | ||
*/ | ||
function reactive(setup) { | ||
return makeReactiveObject(setup); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Makes all values into reactive objects. | ||
*/ | ||
function reactiveAll(setup) { | ||
return makeReactiveObject(setup); | ||
} | ||
function computed(computedCallback) { | ||
@@ -528,3 +546,3 @@ return new ComputedObserver(computedCallback); | ||
export { Computed, ComputedObserver, Observe, Observer, Reactive, ReactiveSubscribe, adaptReactive, camelize, computed, defineObservers, findTarget, getObserver, getObservers, injectReactiveSubscribe, isFunction, isObject, isObserver, isString, keys, observe, reactive, setObserver, withClassMethods, withReactiveMethods }; | ||
export { Computed, ComputedObserver, Observe, Observer, Reactive, ReactiveSubscribe, adaptReactive, camelize, computed, defineObservers, findTarget, getObserver, getObservers, injectReactiveSubscribe, isFunction, isObject, isObserver, isString, keys, observe, reactive, reactiveAll, setObserver, withClassMethods, withReactiveMethods }; | ||
//# sourceMappingURL=cfcs.esm.js.map |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.13 | ||
version: 0.0.14 | ||
*/ | ||
@@ -759,3 +759,3 @@ (function (global, factory) { | ||
function reactive(setup, all) { | ||
function makeReactiveObject(setup, all) { | ||
var result = isFunction(setup) ? setup() : setup; | ||
@@ -769,5 +769,2 @@ var reactiveObject = {}; | ||
setObserver(reactiveObject, name, value); | ||
} else if (!all) { | ||
reactiveObject[name] = value; | ||
return; | ||
} else { | ||
@@ -782,2 +779,23 @@ setObserver(reactiveObject, name, observe(value)); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Only the values to which observer is applied are objects to which reactive is applied. | ||
*/ | ||
function reactive(setup) { | ||
return makeReactiveObject(setup); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Makes all values into reactive objects. | ||
*/ | ||
function reactiveAll(setup) { | ||
return makeReactiveObject(setup); | ||
} | ||
function computed(computedCallback) { | ||
@@ -950,2 +968,3 @@ return new ComputedObserver(computedCallback); | ||
reactive: reactive, | ||
reactiveAll: reactiveAll, | ||
computed: computed, | ||
@@ -952,0 +971,0 @@ observe: observe, |
@@ -7,5 +7,5 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.13 | ||
version: 0.0.14 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).cfcs=n()}(this,function(){"use strict";function u(t){return Object.keys(t)}function e(t){return"string"==typeof t}function n(t){return"object"==typeof t}function o(t){return"function"==typeof t}var r="__observers__",i=1,c="__CFCS_DETECTED_DEPENDENCIES__",f=function(t,n){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])})(t,n)};function s(){Object[c]=Object[c]||{};var t=Object[c];return t[i]=t[i]||[],t[i]}function a(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function l(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||0<n--)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u}(arguments[n]));return t}function h(t){return void 0===t}var v=function(){function t(t,n){var e,r;if(this._canceled=!1,n)try{for(var i=a(Object.keys(n)),o=i.next();!o.done;o=i.next()){var u=o.value;this[u]=n[u]}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}this.eventType=t}var n=t.prototype;return n.stop=function(){this._canceled=!0},n.isCanceled=function(){return this._canceled},t}(),p=function(){function t(){this._eventHandler={}}var n=t.prototype;return n.trigger=function(n){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var r=n instanceof v?n.eventType:n,r=l(this._eventHandler[r]||[]);return r.length<=0||(n instanceof v?(n.currentTarget=this,r.forEach(function(t){t(n)})):r.forEach(function(t){t.apply(void 0,l(e))})),this},n.once=function(e,r){var i,o=this;if("object"==typeof e&&h(r)){var t,n=e;for(t in n)this.once(t,n[t])}else"string"==typeof e&&"function"==typeof r&&(i=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.apply(void 0,l(t)),o.off(e,i)},this.on(e,i));return this},n.hasOn=function(t){return!!this._eventHandler[t]},n.on=function(t,n){if("object"==typeof t&&h(n)){var e,r=t;for(e in r)this.on(e,r[e])}else{var i;"string"==typeof t&&"function"==typeof n&&(i=this._eventHandler[t],h(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(n))}return this},n.off=function(t,n){var e,r;if(h(t))return this._eventHandler={},this;if(h(n)){if("string"==typeof t)return delete this._eventHandler[t],this;var i,o=t;for(i in o)this.off(i,o[i])}else{var u=this._eventHandler[t];if(u){var c=0;try{for(var f=a(u),s=f.next();!s.done;s=f.next()){if(s.value===n){u.splice(c,1),u.length<=0&&delete this._eventHandler[t];break}c++}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=f.return)&&r.call(f)}finally{if(e)throw e.error}}}}return this},t.VERSION="3.0.3",t}(),d=function(){function t(t){this._emitter=new p,this._current=t}var n=t.prototype;return Object.defineProperty(n,"current",{get:function(){var t=(t=s())[t.length-1];return null!=t&&t.push(this),this._current},set:function(t){this._setCurrent(t)},enumerable:!1,configurable:!0}),n.subscribe=function(t){return this.current,this._emitter.on("update",t),this},n.unsubscribe=function(t){return this._emitter.off("update",t),this},n._setCurrent=function(t){var n=this._current,e=t!==n;this._current=t,e&&this._emitter.trigger("update",t,n)},n.toString=function(){return"".concat(this.current)},n.valueOf=function(){return this.current},t}(),b=function(e){var t=i,n=e;if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}function i(t){var n=e.call(this)||this;return n._computedCallback=t,n._registered=[],n._onCheckUpdate=function(){n._setCurrent(n.current)},n._current=n.current,n}return f(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r),Object.defineProperty(i.prototype,"current",{get:function(){var n,e,r=this,t=(n=this,t=s(),i={host:n,observers:e=[],push:function(t){n!==t&&-1===e.indexOf(t)&&e.push(t)}},t.push(i),this._computedCallback()),i=s().pop();return this._registered.forEach(function(t){t.unsubscribe(r._onCheckUpdate)}),i.observers.forEach(function(t){t.subscribe(r._onCheckUpdate)}),this._registered=i.observers,t},enumerable:!1,configurable:!0}),i}(d);function y(t,n,e){void 0===e&&(e=n),Object.defineProperty(t,n,{configurable:!0,get:function(){return w(this,e).current},set:function(t){w(this,e,t).current=t}}),e!==n&&Object.defineProperty(t,e,{configurable:!0,get:function(){return w(this,e).current}})}function _(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1<e.length?y(e[0],e[1]):function(t,n){return y(t,n,e[0])}}function g(t){t.subscribe=function(t,n){this[t],w(this,t).subscribe(n)},t.unsubscribe=function(t,n){var e=this;t?t in this&&w(this,t).unsubscribe(n):u(C(this)).forEach(function(t){e.unsubscribe(t)})}}function O(t){return new b(t)}function m(t){return new d(t)}function j(i,t){var n={};return t&&t.forEach(function(r){n[r]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=i.current||i.value;return e[r].apply(e,t)}}),n}function E(t){var n={};return Object.defineProperty(t,r,{get:function(){return n}}),n}function C(t){return t[r]||E(t),t[r]}function w(t,n,e){t=C(t);return t[n]||(t[n]=m(e)),t[n]}function S(t,n,e){C(t)[n]=e}function x(t){return t&&n(t)&&"current"in t&&"subscribe"in t&&"unsubscribe"in t}return{__proto__:null,keys:u,camelize:function(t){return t.replace(/[\s-_]([a-z])/g,function(t,n){return n.toUpperCase()})},isString:e,isObject:n,isFunction:o,findTarget:function(t){var n;return t?(e(t)?n=document.querySelector(t):t instanceof Element?n=t:("value"in t||"current"in t)&&(n=t.value||t.current),n):null},withClassMethods:function(n){return function(t,i){n.forEach(function(r){r in t||(t[r]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(e=this[i])[r].apply(e,t);return e===this[i]?this:e})})}},withReactiveMethods:j,defineObservers:E,getObservers:C,getObserver:w,setObserver:S,isObserver:x,Observer:d,ComputedObserver:b,reactive:function(t,e){var r=o(t)?t():t,i={};return E(i),u(r).forEach(function(t){var n=r[t];if(x(n))S(i,t,n);else{if(!e)return void(i[t]=n);S(i,t,m(n))}_(t)(i,t)}),g(i),i},computed:O,observe:m,adaptReactive:function(r){var t;function n(){var t;return null!=(t=null==(t=r.data)?void 0:t.call(r))?t:{}}var i={current:(null==(t=r.created)?void 0:t.call(r,n()))||null},o=null;return{state:function(){var e,t=i.current;return o||(r.state?o=r.state:t&&(e=C(t),o=u(e).reduce(function(t,n){return t[n]=e[n].current,t},{})),o||{})},instance:function(){return i.current},mounted:function(){var t;i.current=(null==(t=r.mounted)?void 0:t.call(r,n(),i.current))||i.current},init:function(){var t;null!=(t=r.init)&&t.call(r,i.current,n())},destroy:function(){var t;null!=(t=r.destroy)&&t.call(r,i.current,n())},methods:function(){return j(i,r.methods)},on:function(t,n){var e;null!=(e=r.on)&&e.call(r,i.current,t,n)},off:function(t,n){var e;null!=(e=r.off)&&e.call(r,i.current,t,n)}}},Observe:_,Reactive:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return _.apply(void 0,t)},Computed:function(t,n,e){var r=e.get;return e={configurable:!0,get:function(){var t=C(this);return n in t||(t[n]=O(r.bind(this))),w(this,n).current}},Object.defineProperty(t,n,e),e},injectReactiveSubscribe:g,ReactiveSubscribe:function(t){g(t.prototype)}}}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).cfcs=n()}(this,function(){"use strict";function u(t){return Object.keys(t)}function e(t){return"string"==typeof t}function n(t){return"object"==typeof t}function i(t){return"function"==typeof t}var r="__observers__",o=1,c="__CFCS_DETECTED_DEPENDENCIES__",f=function(t,n){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])})(t,n)};function s(){Object[c]=Object[c]||{};var t=Object[c];return t[o]=t[o]||[],t[o]}function a(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function l(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||0<n--)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u}(arguments[n]));return t}function h(t){return void 0===t}var v=function(){function t(t,n){var e,r;if(this._canceled=!1,n)try{for(var i=a(Object.keys(n)),o=i.next();!o.done;o=i.next()){var u=o.value;this[u]=n[u]}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}this.eventType=t}var n=t.prototype;return n.stop=function(){this._canceled=!0},n.isCanceled=function(){return this._canceled},t}(),p=function(){function t(){this._eventHandler={}}var n=t.prototype;return n.trigger=function(n){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var r=n instanceof v?n.eventType:n,r=l(this._eventHandler[r]||[]);return r.length<=0||(n instanceof v?(n.currentTarget=this,r.forEach(function(t){t(n)})):r.forEach(function(t){t.apply(void 0,l(e))})),this},n.once=function(e,r){var i,o=this;if("object"==typeof e&&h(r)){var t,n=e;for(t in n)this.once(t,n[t])}else"string"==typeof e&&"function"==typeof r&&(i=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.apply(void 0,l(t)),o.off(e,i)},this.on(e,i));return this},n.hasOn=function(t){return!!this._eventHandler[t]},n.on=function(t,n){if("object"==typeof t&&h(n)){var e,r=t;for(e in r)this.on(e,r[e])}else{var i;"string"==typeof t&&"function"==typeof n&&(i=this._eventHandler[t],h(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(n))}return this},n.off=function(t,n){var e,r;if(h(t))return this._eventHandler={},this;if(h(n)){if("string"==typeof t)return delete this._eventHandler[t],this;var i,o=t;for(i in o)this.off(i,o[i])}else{var u=this._eventHandler[t];if(u){var c=0;try{for(var f=a(u),s=f.next();!s.done;s=f.next()){if(s.value===n){u.splice(c,1),u.length<=0&&delete this._eventHandler[t];break}c++}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=f.return)&&r.call(f)}finally{if(e)throw e.error}}}}return this},t.VERSION="3.0.3",t}(),d=function(){function t(t){this._emitter=new p,this._current=t}var n=t.prototype;return Object.defineProperty(n,"current",{get:function(){var t=(t=s())[t.length-1];return null!=t&&t.push(this),this._current},set:function(t){this._setCurrent(t)},enumerable:!1,configurable:!0}),n.subscribe=function(t){return this.current,this._emitter.on("update",t),this},n.unsubscribe=function(t){return this._emitter.off("update",t),this},n._setCurrent=function(t){var n=this._current,e=t!==n;this._current=t,e&&this._emitter.trigger("update",t,n)},n.toString=function(){return"".concat(this.current)},n.valueOf=function(){return this.current},t}(),b=function(e){var t=i,n=e;if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}function i(t){var n=e.call(this)||this;return n._computedCallback=t,n._registered=[],n._onCheckUpdate=function(){n._setCurrent(n.current)},n._current=n.current,n}return f(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r),Object.defineProperty(i.prototype,"current",{get:function(){var n,e,r=this,t=(n=this,t=s(),i={host:n,observers:e=[],push:function(t){n!==t&&-1===e.indexOf(t)&&e.push(t)}},t.push(i),this._computedCallback()),i=s().pop();return this._registered.forEach(function(t){t.unsubscribe(r._onCheckUpdate)}),i.observers.forEach(function(t){t.subscribe(r._onCheckUpdate)}),this._registered=i.observers,t},enumerable:!1,configurable:!0}),i}(d);function y(t,n,e){void 0===e&&(e=n),Object.defineProperty(t,n,{configurable:!0,get:function(){return w(this,e).current},set:function(t){w(this,e,t).current=t}}),e!==n&&Object.defineProperty(t,e,{configurable:!0,get:function(){return w(this,e).current}})}function _(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1<e.length?y(e[0],e[1]):function(t,n){return y(t,n,e[0])}}function g(t){t.subscribe=function(t,n){this[t],w(this,t).subscribe(n)},t.unsubscribe=function(t,n){var e=this;t?t in this&&w(this,t).unsubscribe(n):u(C(this)).forEach(function(t){e.unsubscribe(t)})}}function t(t){var e=i(t)?t():t,r={};return E(r),u(e).forEach(function(t){var n=e[t];x(n)?S(r,t,n):S(r,t,m(n)),_(t)(r,t)}),g(r),r}function O(t){return new b(t)}function m(t){return new d(t)}function j(i,t){var n={};return t&&t.forEach(function(r){n[r]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=i.current||i.value;return e[r].apply(e,t)}}),n}function E(t){var n={};return Object.defineProperty(t,r,{get:function(){return n}}),n}function C(t){return t[r]||E(t),t[r]}function w(t,n,e){t=C(t);return t[n]||(t[n]=m(e)),t[n]}function S(t,n,e){C(t)[n]=e}function x(t){return t&&n(t)&&"current"in t&&"subscribe"in t&&"unsubscribe"in t}return{__proto__:null,keys:u,camelize:function(t){return t.replace(/[\s-_]([a-z])/g,function(t,n){return n.toUpperCase()})},isString:e,isObject:n,isFunction:i,findTarget:function(t){var n;return t?(e(t)?n=document.querySelector(t):t instanceof Element?n=t:("value"in t||"current"in t)&&(n=t.value||t.current),n):null},withClassMethods:function(n){return function(t,i){n.forEach(function(r){r in t||(t[r]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(e=this[i])[r].apply(e,t);return e===this[i]?this:e})})}},withReactiveMethods:j,defineObservers:E,getObservers:C,getObserver:w,setObserver:S,isObserver:x,Observer:d,ComputedObserver:b,reactive:t,reactiveAll:t,computed:O,observe:m,adaptReactive:function(r){var t;function n(){var t;return null!=(t=null==(t=r.data)?void 0:t.call(r))?t:{}}var i={current:(null==(t=r.created)?void 0:t.call(r,n()))||null},o=null;return{state:function(){var e,t=i.current;return o||(r.state?o=r.state:t&&(e=C(t),o=u(e).reduce(function(t,n){return t[n]=e[n].current,t},{})),o||{})},instance:function(){return i.current},mounted:function(){var t;i.current=(null==(t=r.mounted)?void 0:t.call(r,n(),i.current))||i.current},init:function(){var t;null!=(t=r.init)&&t.call(r,i.current,n())},destroy:function(){var t;null!=(t=r.destroy)&&t.call(r,i.current,n())},methods:function(){return j(i,r.methods)},on:function(t,n){var e;null!=(e=r.on)&&e.call(r,i.current,t,n)},off:function(t,n){var e;null!=(e=r.off)&&e.call(r,i.current,t,n)}}},Observe:_,Reactive:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return _.apply(void 0,t)},Computed:function(t,n,e){var r=e.get;return e={configurable:!0,get:function(){var t=C(this);return n in t||(t[n]=O(r.bind(this))),w(this,n).current}},Object.defineProperty(t,n,e),e},injectReactiveSubscribe:g,ReactiveSubscribe:function(t){g(t.prototype)}}}); | ||
//# sourceMappingURL=cfcs.min.js.map |
{ | ||
"name": "@cfcs/core", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/cfcs.cjs.js", |
@@ -14,3 +14,3 @@ import { keys } from "../core"; | ||
Events extends Record<string, any> = {}, | ||
>(adapter: ReactiveAdapter<Instance, State, Methods, Data, Events>) { | ||
>(adapter: ReactiveAdapter<Instance, State, Methods, Data, Events>) { | ||
@@ -17,0 +17,0 @@ function data(): Data { |
@@ -6,19 +6,19 @@ import { computed } from "../inline"; | ||
export function Computed(prototype: any, memberName: string, attributes: PropertyDescriptor): PropertyDescriptor { | ||
const get = attributes.get!; | ||
function getComputed() { | ||
const observers = getObservers(this); | ||
const get = attributes.get!; | ||
function getComputed() { | ||
const observers = getObservers(this); | ||
if (!(memberName in observers)) { | ||
observers[memberName] = computed(get.bind(this)); | ||
} | ||
return getObserver(this, memberName).current; | ||
if (!(memberName in observers)) { | ||
observers[memberName] = computed(get.bind(this)); | ||
} | ||
const nextAttributes: PropertyDescriptor = { | ||
configurable: true, | ||
get: getComputed, | ||
} | ||
return getObserver(this, memberName).current; | ||
} | ||
const nextAttributes: PropertyDescriptor = { | ||
configurable: true, | ||
get: getComputed, | ||
} | ||
Object.defineProperty(prototype, memberName, nextAttributes); | ||
Object.defineProperty(prototype, memberName, nextAttributes); | ||
return nextAttributes; | ||
return nextAttributes; | ||
} |
@@ -24,2 +24,3 @@ import { getObserver } from "../utils"; | ||
} | ||
export function Observe(protoype: any, memberName: string): void; | ||
@@ -26,0 +27,0 @@ export function Observe(name?: string): (protoype: any, memberName: string) => void; |
@@ -31,2 +31,3 @@ import { keys } from "../../core"; | ||
* @typedef | ||
* @memberof Reactive | ||
*/ | ||
@@ -33,0 +34,0 @@ export interface ReactiveSubscribe<State extends Record<string, any>> { |
@@ -17,6 +17,12 @@ import { ComputedObserver } from "./ComputedObserver"; | ||
/** | ||
* @typedef | ||
* @memberof Reactive | ||
* @extends Reactive.ReactiveSubscribe | ||
*/ | ||
export type ReactiveObject<Object extends Record<string, any>> | ||
= ConvertValue<Object> & ReactiveSubscribe<PickObverser<Object>>; | ||
export function reactive<Object extends Record<string, any>>( | ||
function makeReactiveObject<Object extends Record<string, any>>( | ||
setup: Readonly<Object> | (() => Readonly<Object>), | ||
@@ -34,5 +40,2 @@ all?: boolean, | ||
setObserver(reactiveObject, name, value); | ||
} else if (!all) { | ||
reactiveObject[name] = value; | ||
return; | ||
} else { | ||
@@ -48,8 +51,32 @@ setObserver(reactiveObject, name, observe(value)); | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Only the values to which observer is applied are objects to which reactive is applied. | ||
*/ | ||
export function reactive<Object extends Record<string, any>>( | ||
setup: Readonly<Object> | (() => Readonly<Object>), | ||
): ReactiveObject<Object> { | ||
return makeReactiveObject(setup); | ||
} | ||
/** | ||
* Make the return value of the corresponding object or function a reactive object. | ||
* @memberof Reactive | ||
* @param setup - The target object or function to which reactive is applied | ||
* @returns Makes all values into reactive objects. | ||
*/ | ||
export function reactiveAll<Object extends Record<string, any>>( | ||
setup: Readonly<Object> | (() => Readonly<Object>), | ||
): ReactiveObject<Object> { | ||
return makeReactiveObject(setup, true); | ||
} | ||
export function computed<Type>(computedCallback: () => Type) { | ||
return new ComputedObserver(computedCallback); | ||
return new ComputedObserver(computedCallback); | ||
} | ||
export function observe<Type>(defaultValue?: Type): Observer<Type> { | ||
return new Observer<Type>(defaultValue); | ||
return new Observer<Type>(defaultValue); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
240536
2923