@cfcs/core
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,2 +5,3 @@ import { ReactiveAdapter } from "./ReactiveAdapter"; | ||
export declare function adaptReactive<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = {}, Methods extends keyof Partial<Instance> = any, Data = any, Events extends Record<string, any> = {}>(adapter: ReactiveAdapter<Instance, State, Methods, Data, Events>): { | ||
state(): State; | ||
instance(): Instance; | ||
@@ -7,0 +8,0 @@ mounted(): void; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.1 | ||
version: 0.0.2 | ||
*/ | ||
@@ -218,3 +218,23 @@ 'use strict'; | ||
}; | ||
var firstState = null; | ||
return { | ||
state: function () { | ||
var inst = instanceRef.current; | ||
if (firstState) { | ||
return firstState; | ||
} | ||
if (adapter.state) { | ||
firstState = adapter.state; | ||
} else if (inst) { | ||
var observers_1 = getObservers(inst); | ||
firstState = keys(observers_1).reduce(function (prev, cur) { | ||
prev[cur] = observers_1[cur].current; | ||
return prev; | ||
}, {}); | ||
} | ||
return firstState || {}; | ||
}, | ||
instance: function () { | ||
@@ -221,0 +241,0 @@ return instanceRef.current; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.1 | ||
version: 0.0.2 | ||
*/ | ||
@@ -216,3 +216,23 @@ import Component from '@egjs/component'; | ||
}; | ||
var firstState = null; | ||
return { | ||
state: function () { | ||
var inst = instanceRef.current; | ||
if (firstState) { | ||
return firstState; | ||
} | ||
if (adapter.state) { | ||
firstState = adapter.state; | ||
} else if (inst) { | ||
var observers_1 = getObservers(inst); | ||
firstState = keys(observers_1).reduce(function (prev, cur) { | ||
prev[cur] = observers_1[cur].current; | ||
return prev; | ||
}, {}); | ||
} | ||
return firstState || {}; | ||
}, | ||
instance: function () { | ||
@@ -219,0 +239,0 @@ return instanceRef.current; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.1 | ||
version: 0.0.2 | ||
*/ | ||
@@ -681,3 +681,23 @@ (function (global, factory) { | ||
}; | ||
var firstState = null; | ||
return { | ||
state: function () { | ||
var inst = instanceRef.current; | ||
if (firstState) { | ||
return firstState; | ||
} | ||
if (adapter.state) { | ||
firstState = adapter.state; | ||
} else if (inst) { | ||
var observers_1 = getObservers(inst); | ||
firstState = keys(observers_1).reduce(function (prev, cur) { | ||
prev[cur] = observers_1[cur].current; | ||
return prev; | ||
}, {}); | ||
} | ||
return firstState || {}; | ||
}, | ||
instance: function () { | ||
@@ -684,0 +704,0 @@ return instanceRef.current; |
@@ -7,5 +7,5 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.1 | ||
version: 0.0.2 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).cfcs=n()}(this,function(){"use strict";function i(t){return Object.keys(t)}var n="__observers__";function s(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 u(){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 l(t){return void 0===t}var o=function(){function t(t,n){var e,r;if(this._canceled=!1,n)try{for(var i=s(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}(),e=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 o?n.eventType:n,r=u(this._eventHandler[r]||[]);return r.length<=0||(n instanceof o?(n.currentTarget=this,r.forEach(function(t){t(n)})):r.forEach(function(t){t.apply(void 0,u(e))})),this},n.once=function(e,r){var i,o=this;if("object"==typeof e&&l(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,u(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&&l(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],l(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(n))}return this},n.off=function(t,n){var e,r;if(l(t))return this._eventHandler={},this;if(l(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=s(u),a=f.next();!a.done;a=f.next()){if(a.value===n){u.splice(c,1),u.length<=0&&delete this._eventHandler[t];break}c++}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=f.return)&&r.call(f)}finally{if(e)throw e.error}}}}return this},t.VERSION="3.0.2",t}(),c=function(){function t(t){this._emitter=new e,this._current=t}var n=t.prototype;return Object.defineProperty(n,"current",{get:function(){return this._current},set:function(t){var n=t!==this._current;this._current=t,n&&this._emitter.trigger("update",t)},enumerable:!1,configurable:!0}),n.subscribe=function(t){this._emitter.on("update",t)},n.unsubscribe=function(t){this._emitter.off("update",t)},t}();function f(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 r(t){return new c(t)}function a(t){return t[n]||(t[n]={}),t[n]}function v(t,n,e){t=a(t);return t[n]||(t[n]=r(e)),t[n]}function h(t,n,e){a(t)[n]=e}function d(r){return function(t,n){var e=r||n;Object.defineProperty(t,n,{get:function(){return v(this,e).current},set:function(t){v(this,e,t).current=t}}),e!==n&&Object.defineProperty(t,e,{get:function(){return v(this,e).current}})}}function p(t){t.subscribe=function(t,n){v(this,t).subscribe(n)},t.unsubscribe=function(t,n){var e=this;t?t in this&&v(this,t).unsubscribe(n):i(a(this)).forEach(function(t){e.unsubscribe(t)})}}return{__proto__:null,keys:i,camelize:function(t){return t.replace(/[\s-_]([a-z])/g,function(t,n){return n.toUpperCase()})},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:f,observe:r,getObservers:a,getObserver:v,setObserver:h,Observer:c,reactive:function(t){var e=t(),r={};return i(e).forEach(function(t){var n=e[t];n instanceof c?(h(r,t,n),d(t)(r,t)):r[t]=n}),p(r),r},Reactive:d,injectReactiveSubscribe:p,ReactiveSubscribe:function(t){p(t.prototype)},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=null==(t=r.created)?void 0:t.call(r,n()))?t:null};return{instance:function(){return i.current},mounted:function(){var t;i.current=(null==(t=r.mounted)?void 0:t.call(r,n()))||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 f(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)}}}}}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).cfcs=n()}(this,function(){"use strict";function u(t){return Object.keys(t)}var n="__observers__";function s(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 c(){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 l(t){return void 0===t}var i=function(){function t(t,n){var e,r;if(this._canceled=!1,n)try{for(var i=s(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}(),e=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 i?n.eventType:n,r=c(this._eventHandler[r]||[]);return r.length<=0||(n instanceof i?(n.currentTarget=this,r.forEach(function(t){t(n)})):r.forEach(function(t){t.apply(void 0,c(e))})),this},n.once=function(e,r){var i,o=this;if("object"==typeof e&&l(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,c(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&&l(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],l(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(n))}return this},n.off=function(t,n){var e,r;if(l(t))return this._eventHandler={},this;if(l(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=s(u),a=f.next();!a.done;a=f.next()){if(a.value===n){u.splice(c,1),u.length<=0&&delete this._eventHandler[t];break}c++}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=f.return)&&r.call(f)}finally{if(e)throw e.error}}}}return this},t.VERSION="3.0.2",t}(),o=function(){function t(t){this._emitter=new e,this._current=t}var n=t.prototype;return Object.defineProperty(n,"current",{get:function(){return this._current},set:function(t){var n=t!==this._current;this._current=t,n&&this._emitter.trigger("update",t)},enumerable:!1,configurable:!0}),n.subscribe=function(t){this._emitter.on("update",t)},n.unsubscribe=function(t){this._emitter.off("update",t)},t}();function f(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 r(t){return new o(t)}function a(t){return t[n]||(t[n]={}),t[n]}function v(t,n,e){t=a(t);return t[n]||(t[n]=r(e)),t[n]}function h(t,n,e){a(t)[n]=e}function d(r){return function(t,n){var e=r||n;Object.defineProperty(t,n,{get:function(){return v(this,e).current},set:function(t){v(this,e,t).current=t}}),e!==n&&Object.defineProperty(t,e,{get:function(){return v(this,e).current}})}}function p(t){t.subscribe=function(t,n){v(this,t).subscribe(n)},t.unsubscribe=function(t,n){var e=this;t?t in this&&v(this,t).unsubscribe(n):u(a(this)).forEach(function(t){e.unsubscribe(t)})}}return{__proto__:null,keys:u,camelize:function(t){return t.replace(/[\s-_]([a-z])/g,function(t,n){return n.toUpperCase()})},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:f,observe:r,getObservers:a,getObserver:v,setObserver:h,Observer:o,reactive:function(t){var e=t(),r={};return u(e).forEach(function(t){var n=e[t];n instanceof o?(h(r,t,n),d(t)(r,t)):r[t]=n}),p(r),r},Reactive:d,injectReactiveSubscribe:p,ReactiveSubscribe:function(t){p(t.prototype)},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=null==(t=r.created)?void 0:t.call(r,n()))?t:null},o=null;return{state:function(){var e,t=i.current;return o||(r.state?o=r.state:t&&(e=a(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},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 f(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)}}}}}); | ||
//# sourceMappingURL=cfcs.min.js.map |
{ | ||
"name": "@cfcs/core", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/cfcs.cjs.js", |
@@ -0,1 +1,2 @@ | ||
import { keys } from "src/core"; | ||
import { Ref } from "src/core/types"; | ||
@@ -5,3 +6,3 @@ import { ReactiveAdapter } from "./ReactiveAdapter"; | ||
import { ReactiveEventCallback } from "./types"; | ||
import { withReactiveMethods } from "./utils"; | ||
import { getObservers, withReactiveMethods } from "./utils"; | ||
@@ -21,4 +22,22 @@ export function adaptReactive< | ||
const instanceRef: Ref<Instance> = { current: adapter.created?.(data()) ?? null }; | ||
let firstState: State | null = null; | ||
return { | ||
state(): State { | ||
const inst = instanceRef.current; | ||
if (firstState) { | ||
return firstState; | ||
} | ||
if (adapter.state) { | ||
firstState = adapter.state; | ||
} else if (inst) { | ||
const observers = getObservers(inst); | ||
return { | ||
firstState = keys(observers).reduce((prev, cur) => { | ||
prev[cur] = observers[cur].current; | ||
return prev; | ||
}, {} as any); | ||
} | ||
return firstState || {} as State; | ||
}, | ||
instance() { | ||
@@ -25,0 +44,0 @@ return instanceRef.current; |
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
123346
1682