@cfcs/core
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -1,5 +0,5 @@ | ||
import { ReactiveAdapter } from "./ReactiveAdapter"; | ||
import { ReactiveAdapterParam } from "./ReactiveAdapter"; | ||
import { ReactiveSubscribe } from "./decorators/ReactiveSubscribe"; | ||
import { ReactiveEventCallback, ReactiveState } from "./types"; | ||
export declare function adaptReactive<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = any, Props = any, Events extends Record<string, any> = {}>(adapter: ReactiveAdapter<Instance, State, Methods, Props, Events>, props?: () => Props): { | ||
export declare function adaptReactive<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = any, Props = any, Events extends Record<string, any> = {}>(adapter: ReactiveAdapterParam<Instance, State, Methods, Props, Events>, props?: () => Props): { | ||
events: () => readonly (keyof Events)[]; | ||
@@ -6,0 +6,0 @@ state(): State; |
@@ -28,5 +28,5 @@ import { EventKey, EventTriggerParams } from "@egjs/component/declaration/types"; | ||
} | ||
export declare type ReactiveAdapter<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = never, Props = any, Events extends Record<string, any> = {}> = ReactiveObjectAdapter<Instance, State, Methods, Props, Events> | ReactiveSetupAdapter<Instance, State, Methods, Props, Events>; | ||
export declare type ReactiveAdapterParam<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = never, Props = any, Events extends Record<string, any> = {}> = ReactiveAdapter<Instance, State, Methods, Props, Events> | ReactiveSetupAdapter<Instance, State, Methods, Props, Events>; | ||
export declare type ReactiveSetupAdapter<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = never, Props = any, Events extends Record<string, any> = {}> = (setup: ReacitveSetup<Instance, State, Methods, Props, Events>) => Instance | undefined | void; | ||
export interface ReactiveObjectAdapter<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = never, Props = any, Events extends Record<string, any> = {}> { | ||
export interface ReactiveAdapter<Instance extends ReactiveSubscribe<Record<string, any>>, State extends Record<string, any> = ReactiveState<Instance>, Methods extends keyof Partial<Instance> = never, Props = any, Events extends Record<string, any> = {}> { | ||
/** | ||
@@ -33,0 +33,0 @@ * Specify if you want to use the framework's state. If an instance is created through created, it can be omitted. |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.19 | ||
version: 0.0.20 | ||
*/ | ||
@@ -10,0 +10,0 @@ 'use strict'; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.19 | ||
version: 0.0.20 | ||
*/ | ||
@@ -10,0 +10,0 @@ import Component from '@egjs/component'; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.19 | ||
version: 0.0.20 | ||
*/ | ||
@@ -10,0 +10,0 @@ (function (global, factory) { |
@@ -7,5 +7,5 @@ /* | ||
repository: https://github.com/naver/cfcs | ||
version: 0.0.19 | ||
version: 0.0.20 | ||
*/ | ||
!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 m(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__",o=1,i="__CFCS_DETECTED_DEPENDENCIES__",u=function(t,n){return(u=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 E(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||((r=r||Array.prototype.slice.call(n,0,o))[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}function c(){Object[i]=Object[i]||{};var t=Object[i];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 f(){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,o,i=e.call(t),u=[];try{for(;(void 0===n||0<n--)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}(arguments[n]));return t}function l(t){return void 0===t}var s=function(){function t(t,n){var e,r;if(this._canceled=!1,n)try{for(var o=a(Object.keys(n)),i=o.next();!i.done;i=o.next()){var u=i.value;this[u]=n[u]}}catch(t){e={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}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}(),j=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 s?n.eventType:n,r=f(this._eventHandler[r]||[]);return r.length<=0||(n instanceof s?(n.currentTarget=this,r.forEach(function(t){t(n)})):r.forEach(function(t){t.apply(void 0,f(e))})),this},n.once=function(e,r){var o,i=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&&(o=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.apply(void 0,f(t)),i.off(e,o)},this.on(e,o));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 o;"string"==typeof t&&"function"==typeof n&&(o=this._eventHandler[t],l(o)&&(this._eventHandler[t]=[],o=this._eventHandler[t]),o.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 o,i=t;for(o in i)this.off(o,i[o])}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}(),h=function(){function t(t){this._emitter=new j,this._current=t}var n=t.prototype;return Object.defineProperty(n,"current",{get:function(){var t=(t=c())[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}(),v=function(e){var t=o,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 o(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 u(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r),Object.defineProperty(o.prototype,"current",{get:function(){var n,e,r=this,t=(n=this,t=c(),o={host:n,observers:e=[],push:function(t){n!==t&&-1===e.indexOf(t)&&e.push(t)}},t.push(o),this._computedCallback()),o=c().pop();return this._registered.forEach(function(t){t.unsubscribe(r._onCheckUpdate)}),o.observers.forEach(function(t){t.subscribe(r._onCheckUpdate)}),this._registered=o.observers,t},enumerable:!1,configurable:!0}),o}(h);function p(t,n,e){void 0===e&&(e=n),Object.defineProperty(t,n,{configurable:!0,get:function(){return S(this,e).current},set:function(t){S(this,e,t).current=t}}),e!==n&&Object.defineProperty(t,e,{configurable:!0,get:function(){return S(this,e).current}})}function d(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1<e.length?p(e[0],e[1]):function(t,n){return p(t,n,e[0])}}function b(t){t.subscribe=function(t,n){this[t],S(this,t).subscribe(n)},t.unsubscribe=function(t,n){var e=this;t?t in this&&S(this,t).unsubscribe(n):m(w(this)).forEach(function(t){e.unsubscribe(t)})}}function t(t){var e=O(t)?t():t,r={};return g(r),m(e).forEach(function(t){var n=e[t];H(n)?x(r,t,n):x(r,t,_(n)),d(t)(r,t)}),b(r),r}function y(t){return new v(t)}function _(t){return new h(t)}function C(o,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=o.current||o.value;return e[r].apply(e,t)}}),n}function g(t){var n={};return Object.defineProperty(t,r,{get:function(){return n}}),n}function w(t){return t[r]||g(t),t[r]}function S(t,n,e){t=w(t);return t[n]||(t[n]=_(e)),t[n]}function x(t,n,e){w(t)[n]=e}function H(t){return t&&n(t)&&"current"in t&&"subscribe"in t&&"unsubscribe"in t}return{__proto__:null,keys:m,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,o){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[o])[r].apply(e,t);return e===this[o]?this:e})})}},withReactiveMethods:C,defineObservers:g,getObservers:w,getObserver:S,setObserver:x,isObserver:H,Observer:h,ComputedObserver:v,reactive:t,reactiveAll:t,computed:y,observe:_,adaptReactive:function(t,n){var i=O(t)?{setup:t}:t;function r(){var t;return null!=(t=null!=(t=null!=(t=null==n?void 0:n())?t:null==(t=i.props)?void 0:t.call(i))?t:null==(t=i.data)?void 0:t.call(i))?t:{}}function e(t){h.push(t)}function o(t){v.push(t)}function u(t){p.push(t)}function c(t){d.push(t)}function f(t){_=t}function s(t){g=t}function a(t){}var l=new j,h=[],v=[],p=[],d=[],b={current:null},y=[],_=null,g=[];return i.setup&&(b.current=i.setup({getProps:r,setInitialState:f,setEvents:s,setMethods:a,onMounted:e,onDestroy:u,onInit:o,emit:function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];l.trigger.apply(l,E([t],n,!1))},on:c})||null),i.created&&(b.current=i.created(r())||null),i.events&&s(i.events),i.state&&f(i.state),i.methods&&i.methods,i.mounted&&e(i.mounted),i.destroy&&u(i.destroy),i.init&&o(i.init),i.on&&c(function(n,e,r){var o=i.on(n,e,r);return function(){var t;o&&o(),null!=(t=i.off)&&t.call(i,n,e,r)}}),{events:function(){return g},state:function(){var e,t=b.current;return _||(t&&(e=w(t),f(m(e).reduce(function(t,n){return t[n]=e[n].current,t},{}))),_||{})},instance:function(){return b.current},mounted:function(){var n=r();h.forEach(function(t){b.current=t(n,b.current)||b.current})},init:function(){var n=b.current,e=r();y=g.map(function(e){function n(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];l.trigger.apply(l,E([e],t,!1))}var r=b.current;return d.map(function(t){return t(r,e,n)}).filter(Boolean)}),v.forEach(function(t){t(n,e)})},destroy:function(){y.forEach(function(t){t.forEach(function(t){t()})}),l.off();var n=b.current,e=r();p.forEach(function(t){t(n,e)})},methods:function(){return C(b,i.methods)},on:function(t,n){l.on(t,n)},off:function(t,n){l.off(t,n)}}},Observe:d,Reactive:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return d.apply(void 0,t)},Computed:function(t,n,e){var r=e.get;return e={configurable:!0,get:function(){var t=w(this);return n in t||(t[n]=y(r.bind(this))),S(this,n).current}},Object.defineProperty(t,n,e),e},injectReactiveSubscribe:b,ReactiveSubscribe:function(t){b(t.prototype)}}}); | ||
//# sourceMappingURL=cfcs.min.js.map |
{ | ||
"name": "@cfcs/core", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/cfcs.cjs.js", |
import { isFunction, keys } from "../core"; | ||
import { Ref } from "../core/types"; | ||
import { ReactiveAdapter, ReactiveObjectAdapter } from "./ReactiveAdapter"; | ||
import { ReactiveAdapter, ReactiveAdapterParam } from "./ReactiveAdapter"; | ||
import { ReactiveSubscribe } from "./decorators/ReactiveSubscribe"; | ||
@@ -16,4 +16,4 @@ import { ReactiveEventCallback, ReactiveState } from "./types"; | ||
Events extends Record<string, any> = {}, | ||
>(adapter: ReactiveAdapter<Instance, State, Methods, Props, Events>, props?: () => Props) { | ||
const objectAdapter: ReactiveObjectAdapter<Instance, State, Methods, Props, Events> = isFunction(adapter) ? { | ||
>(adapter: ReactiveAdapterParam<Instance, State, Methods, Props, Events>, props?: () => Props) { | ||
const objectAdapter: ReactiveAdapter<Instance, State, Methods, Props, Events> = isFunction(adapter) ? { | ||
setup: adapter, | ||
@@ -20,0 +20,0 @@ } : adapter; |
@@ -35,3 +35,4 @@ import { EventKey, EventTriggerParams } from "@egjs/component/declaration/types"; | ||
} | ||
export type ReactiveAdapter< | ||
export type ReactiveAdapterParam< | ||
Instance extends ReactiveSubscribe<Record<string, any>>, | ||
@@ -41,4 +42,4 @@ State extends Record<string, any> = ReactiveState<Instance>, | ||
Props = any, | ||
Events extends Record<string, any> = {} | ||
> = ReactiveObjectAdapter<Instance, State, Methods, Props, Events> | ||
Events extends Record<string, any> = {}, | ||
> = ReactiveAdapter<Instance, State, Methods, Props, Events> | ||
| ReactiveSetupAdapter<Instance, State, Methods, Props, Events>; | ||
@@ -54,3 +55,3 @@ | ||
export interface ReactiveObjectAdapter< | ||
export interface ReactiveAdapter< | ||
Instance extends ReactiveSubscribe<Record<string, any>>, | ||
@@ -57,0 +58,0 @@ State extends Record<string, any> = ReactiveState<Instance>, |
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
291420