New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@goldfishjs/composition-api

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@goldfishjs/composition-api - npm Package Compare versions

Comparing version 1.1.17 to 1.1.18

2

lib/checkSetupEnv.js

@@ -6,3 +6,3 @@ import useContextType from './useContextType';

if (env.indexOf(type) + 1 === 0) {
throw new Error("The ".concat(name, " can not use in ").concat(type, " setup flow."));
throw new Error("The ".concat(name, " can not be used in ").concat(type, " setup flow."));
}

@@ -9,0 +9,0 @@

import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
import _inherits from "@babel/runtime/helpers/inherits";
import CommonSetup from './CommonSetup';

@@ -15,8 +10,6 @@

var _super = _createSuper(AppSetup);
function AppSetup() {
_classCallCheck(this, AppSetup);
return _super.apply(this, arguments);
return _possibleConstructorReturn(this, _getPrototypeOf(AppSetup).apply(this, arguments));
}

@@ -23,0 +16,0 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {

@@ -49,4 +45,2 @@ function adopt(value) {

var _super = _createSuper(CommonSetup);
function CommonSetup() {

@@ -57,3 +51,3 @@ var _this;

_this = _super.apply(this, arguments);
_this = _possibleConstructorReturn(this, _getPrototypeOf(CommonSetup).apply(this, arguments));
_this.methods = {};

@@ -60,0 +54,0 @@ return _this;

import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
import _inherits from "@babel/runtime/helpers/inherits";
import CommonSetup from './CommonSetup';

@@ -15,8 +10,6 @@

var _super = _createSuper(ComponentSetup);
function ComponentSetup() {
_classCallCheck(this, ComponentSetup);
return _super.apply(this, arguments);
return _possibleConstructorReturn(this, _getPrototypeOf(ComponentSetup).apply(this, arguments));
}

@@ -23,0 +16,0 @@

import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
import _inherits from "@babel/runtime/helpers/inherits";
import CommonSetup from './CommonSetup';

@@ -15,8 +10,6 @@

var _super = _createSuper(PageSetup);
function PageSetup() {
_classCallCheck(this, PageSetup);
return _super.apply(this, arguments);
return _possibleConstructorReturn(this, _getPrototypeOf(PageSetup).apply(this, arguments));
}

@@ -23,0 +16,0 @@

@@ -8,13 +8,9 @@ import _attachLogic from "@goldfishjs/reactive-connect/lib/attachLogic";

import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _get from "@babel/runtime/helpers/get";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _typeof from "@babel/runtime/helpers/typeof";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
var __decorate = this && this.__decorate || function (decorators, target, key, desc) {

@@ -73,4 +69,2 @@ var c = arguments.length,

var _super2 = _createSuper(BizAppStore);
function BizAppStore() {

@@ -81,3 +75,3 @@ var _this;

_this = _super2.call(this);
_this = _possibleConstructorReturn(this, _getPrototypeOf(BizAppStore).call(this));
_this.stopWatchDeepList = []; // Mount store to the app instance.

@@ -84,0 +78,0 @@

@@ -8,13 +8,9 @@ import _attachLogic from "@goldfishjs/reactive-connect/lib/attachLogic";

import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _get from "@babel/runtime/helpers/get";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _typeof from "@babel/runtime/helpers/typeof";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
var __decorate = this && this.__decorate || function (decorators, target, key, desc) {

@@ -47,4 +43,2 @@ var c = arguments.length,

var _super = _createSuper(BizComponentStore);
function BizComponentStore() {

@@ -55,3 +49,3 @@ var _this;

_this = _super.call(this);
_this = _possibleConstructorReturn(this, _getPrototypeOf(BizComponentStore).call(this));
_this.props = cloneDeep(props);

@@ -58,0 +52,0 @@ _this.stopWatchDeepList = [];

@@ -8,13 +8,9 @@ import _attachLogic from "@goldfishjs/reactive-connect/lib/attachLogic";

import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _get from "@babel/runtime/helpers/get";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _typeof from "@babel/runtime/helpers/typeof";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
var __decorate = this && this.__decorate || function (decorators, target, key, desc) {

@@ -73,4 +69,2 @@ var c = arguments.length,

var _super2 = _createSuper(BizPageStore);
function BizPageStore() {

@@ -81,3 +75,3 @@ var _this;

_this = _super2.call(this);
_this = _possibleConstructorReturn(this, _getPrototypeOf(BizPageStore).call(this));
_this.stopWatchDeepList = [];

@@ -84,0 +78,0 @@ var setup = view.$setup;

{
"name": "@goldfishjs/composition-api",
"version": "1.1.17",
"version": "1.1.18",
"description": "goldfish-composition-api",

@@ -18,21 +18,21 @@ "main": "lib/index.js",

"dependencies": {
"@goldfishjs/core": "^1.1.17",
"@goldfishjs/plugins": "^1.1.17",
"@goldfishjs/reactive": "^1.1.17",
"@goldfishjs/reactive-connect": "^1.1.17",
"@goldfishjs/utils": "^1.1.17",
"@goldfishjs/core": "^1.1.18",
"@goldfishjs/plugins": "^1.1.18",
"@goldfishjs/reactive": "^1.1.18",
"@goldfishjs/reactive-connect": "^1.1.18",
"@goldfishjs/utils": "^1.1.18",
"mini-types": "^0.1.0"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@babel/plugin-transform-classes": "^7.7.0",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.7.1",
"babel-plugin-import": "^1.12.2",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-typescript": "^5.0.1",
"jest": "^24.9.0",
"merge2": "^1.3.0",
"ts-jest": "^23.10.2"
"@babel/core": "7.7.0",
"@babel/plugin-transform-classes": "7.7.0",
"@babel/plugin-transform-runtime": "7.6.2",
"@babel/preset-env": "7.7.1",
"babel-plugin-import": "1.12.2",
"gulp": "4.0.2",
"gulp-babel": "8.0.0",
"gulp-typescript": "5.0.1",
"jest": "24.9.0",
"merge2": "1.3.0",
"ts-jest": "23.10.2"
},

@@ -39,0 +39,0 @@ "types": "./types/index.d.ts",

@@ -1,9 +0,5 @@

export default function appendFn(
options: Record<string, any>,
name: string,
fns: Function[],
) {
export default function appendFn(options: Record<string, any>, name: string, fns: Function[]) {
if (!options[name]) {
options[name] = function (...args: any[]) {
fns.forEach((fn) => {
options[name] = function(...args: any[]) {
fns.forEach(fn => {
fn.call(this, ...args);

@@ -13,5 +9,5 @@ });

} else if (typeof options[name] === 'function') {
options[name] = function (...args: any[]) {
options[name] = function(...args: any[]) {
options[name].call(this, ...args);
fns.forEach((fn) => {
fns.forEach(fn => {
fn.call(this, ...args);

@@ -18,0 +14,0 @@ });

@@ -14,3 +14,3 @@ import useContextType from './useContextType';

if (env.indexOf(type as A) + 1 === 0) {
throw new Error(`The ${name} can not use in ${type} setup flow.`);
throw new Error(`The ${name} can not be used in ${type} setup flow.`);
}

@@ -17,0 +17,0 @@

@@ -30,25 +30,20 @@ import PageSetup from './setup/PageSetup';

*/
export default function integrateLifeCycleMethods<K extends Kind>(
lifeCycleMethods: LifeCycleMethodsType[K][],
) {
return lifeCycleMethods.reduce<OptionsType[K]>(
(prev, cur: LifeCycleMethodsType[K]) => {
(prev as any)[cur] = function (this: any, ...args: any[]) {
const setup: SetupType[K] | undefined = this.$setup;
if (!setup) {
return;
}
export default function integrateLifeCycleMethods<K extends Kind>(lifeCycleMethods: LifeCycleMethodsType[K][]) {
return lifeCycleMethods.reduce<OptionsType[K]>((prev, cur: LifeCycleMethodsType[K]) => {
(prev as any)[cur] = function(this: any, ...args: any[]) {
const setup: SetupType[K] | undefined = this.$setup;
if (!setup) {
return;
}
const fns: Function[] = (setup.getMethod as any)(cur) || [];
let result: any;
for (const i in fns) {
const fn = fns[i];
result = (fn as Function).call(this, ...args);
}
return result;
};
return prev;
},
{},
);
const fns: Function[] = (setup.getMethod as any)(cur) || [];
let result: any;
for (const i in fns) {
const fn = fns[i];
result = (fn as Function).call(this, ...args);
}
return result;
};
return prev;
}, {});
}
import PageSetup from './setup/PageSetup';
export default function integratePageEventMethods(
pageMethods: (keyof tinyapp.IPageEvents)[],
): tinyapp.IPageEvents {
return pageMethods.reduce(
(prev, cur: keyof tinyapp.IPageEvents) => {
(prev as any)[cur] = function (this: any, ...args: any[]) {
const setup: PageSetup | undefined = this.$setup;
if (!setup) {
return;
}
export default function integratePageEventMethods(pageMethods: (keyof tinyapp.IPageEvents)[]): tinyapp.IPageEvents {
return pageMethods.reduce((prev, cur: keyof tinyapp.IPageEvents) => {
(prev as any)[cur] = function(this: any, ...args: any[]) {
const setup: PageSetup | undefined = this.$setup;
if (!setup) {
return;
}
const fns: Function[] = (setup.getMethod as any)(`events.${cur}`) || [];
let result: any;
for (const i in fns) {
const fn = fns[i];
result = (fn as Function).call(this, ...args);
}
return result;
};
return prev;
},
{},
);
const fns: Function[] = (setup.getMethod as any)(`events.${cur}`) || [];
let result: any;
for (const i in fns) {
const fn = fns[i];
result = (fn as Function).call(this, ...args);
}
return result;
};
return prev;
}, {});
}

@@ -5,6 +5,3 @@ import { watchDeep } from '@goldfishjs/reactive';

import PageSetup, { SetupPageInstance, SetupPageStore } from './setup/PageSetup';
import ComponentSetup, {
SetupComponentInstance,
SetupComponentStore,
} from './setup/ComponentSetup';
import ComponentSetup, { SetupComponentInstance, SetupComponentStore } from './setup/ComponentSetup';
import AppSetup, { SetupAppInstance, SetupAppStore } from './setup/AppSetup';

@@ -51,8 +48,3 @@

): (() => void)[];
export default function integrateSetupFunctionResult(
fn: ISetupFunction,
setup: any,
viewInstance: any,
store: any,
) {
export default function integrateSetupFunctionResult(fn: ISetupFunction, setup: any, viewInstance: any, store: any) {
setup.setStoreInstance(store);

@@ -92,17 +84,19 @@ setup.setViewInstance(viewInstance);

const stopList: (() => void)[] = [];
stopList.push(watchDeep(
reactiveCompositionState,
(obj: any, keyPathList, newV, oldV, options) => {
if (!(store as any).isSyncDataSafe) {
return;
}
stopList.push(
watchDeep(
reactiveCompositionState,
(obj: any, keyPathList, newV, oldV, options) => {
if (!(store as any).isSyncDataSafe) {
return;
}
const miniDataSetter = getMiniDataSetter();
miniDataSetter.set(viewInstance, obj, keyPathList, newV, oldV, options);
},
{
immediate: true,
},
));
const miniDataSetter = getMiniDataSetter();
miniDataSetter.set(viewInstance, obj, keyPathList, newV, oldV, options);
},
{
immediate: true,
},
),
);
return stopList;
}

@@ -7,8 +7,3 @@ import { observable, computed } from '@goldfishjs/reactive';

if (
descriptor
&& !descriptor.get
&& !descriptor.set
&& typeof obj[k] === 'function'
) {
if (descriptor && !descriptor.get && !descriptor.set && typeof obj[k] === 'function') {
throw new Error(`Do not put function to the reactive object: ${k}.`);

@@ -15,0 +10,0 @@ }

@@ -13,3 +13,2 @@ import CommonSetup from './CommonSetup';

SetupAppInstance
> {
}
> {}

@@ -24,9 +24,9 @@ import Setup from './Setup';

this.fetchInitDataMethod = isAsync
? async function (this: any) {
await Promise.all([fetchInitDataMethod.call(this), fn.call(this)]);
}
: async function (this: any) {
await fetchInitDataMethod.call(this);
await fn.call(this);
};
? async function(this: any) {
await Promise.all([fetchInitDataMethod.call(this), fn.call(this)]);
}
: async function(this: any) {
await fetchInitDataMethod.call(this);
await fn.call(this);
};
} else {

@@ -33,0 +33,0 @@ this.fetchInitDataMethod = fn;

@@ -11,7 +11,2 @@ import CommonSetup from './CommonSetup';

export default class ComponentSetup extends CommonSetup<
Methods,
SetupComponentStore,
SetupComponentInstance
> {
}
export default class ComponentSetup extends CommonSetup<Methods, SetupComponentStore, SetupComponentInstance> {}

@@ -13,3 +13,2 @@ import CommonSetup from './CommonSetup';

SetupPageInstance
> {
}
> {}

@@ -40,7 +40,3 @@ import { wrap, getCurrent } from './globalStack';

*/
protected add(
map: Record<string, any>,
name: string,
val: any,
) {
protected add(map: Record<string, any>, name: string, val: any) {
if (this.state !== 'START') {

@@ -47,0 +43,0 @@ throw new Error(`Wrong setup state while calling 'add' method: ${this.state}.`);

import integrateLifeCycleMethods from './integrateLifeCycleMethods';
import AppSetup from './setup/AppSetup';
import { AppStore, createApp } from '@goldfishjs/core';
import { AppStore, createApp } from '@goldfishjs/core';
import { IConfig, PluginClass } from '@goldfishjs/plugins';

@@ -49,3 +49,3 @@ import integrateSetupFunctionResult, { ISetupFunction } from './integrateSetupFunctionResult';

const fn = view.$setup!.getFetchInitDataMethod();
fn && await fn();
fn && (await fn());
}

@@ -60,18 +60,13 @@

options = createApp(
config,
BizAppStore,
options,
{
beforeCreateStore: (v: View) => {
const setup = new AppSetup();
v.$setup = setup;
view = v;
options = createApp(config, BizAppStore, options, {
beforeCreateStore: (v: View) => {
const setup = new AppSetup();
v.$setup = setup;
view = v;
setup.iterateMethods((fns, name) => {
appendFn(v, name, fns);
});
},
setup.iterateMethods((fns, name) => {
appendFn(v, name, fns);
});
},
);
});

@@ -86,3 +81,3 @@ const lifeCycleMethods: ('onLaunch' | 'onShow' | 'onHide' | 'onError' | 'onShareAppMessage')[] = [

const lifeCycleMethodsOptions = integrateLifeCycleMethods<'app'>(lifeCycleMethods);
lifeCycleMethods.forEach((m) => {
lifeCycleMethods.forEach(m => {
attachLogic(options, m, 'after', lifeCycleMethodsOptions[m] as any);

@@ -89,0 +84,0 @@ });

@@ -28,7 +28,4 @@ import { observable, IProps, state, attachLogic } from '@goldfishjs/reactive-connect';

) {
const props: P = typeof passInProps === 'object' ? passInProps : {} as P;
const fn = (
typeof passInProps === 'function'
? passInProps : passInFn
) as ISetupFunction;
const props: P = typeof passInProps === 'object' ? passInProps : ({} as P);
const fn = (typeof passInProps === 'function' ? passInProps : passInFn) as ISetupFunction;

@@ -69,20 +66,16 @@ let options: tinyapp.ComponentOptions<P, D, {}> = {

options = createComponent<AppStore, BizComponentStore, P, D>(
BizComponentStore,
options,
{
beforeCreateStore: (v: View) => {
const setup = new ComponentSetup();
v.$setup = setup;
view = v;
options = createComponent<AppStore, BizComponentStore, P, D>(BizComponentStore, options, {
beforeCreateStore: (v: View) => {
const setup = new ComponentSetup();
v.$setup = setup;
view = v;
setup.iterateMethods((fns, name) => {
appendFn(v, name, fns as Function[]);
});
},
setup.iterateMethods((fns, name) => {
appendFn(v, name, fns as Function[]);
});
},
);
}) as any;
const lifeCycleMethodsOptions = integrateLifeCycleMethods<'component'>(lifeCycleMethods);
lifeCycleMethods.forEach((m) => {
lifeCycleMethods.forEach(m => {
attachLogic(options, m, 'after', lifeCycleMethodsOptions[m] as any);

@@ -89,0 +82,0 @@ });

@@ -25,5 +25,3 @@ import { createPage, AppStore, PageStore } from '@goldfishjs/core';

export default function setupPage<D, AS extends AppStore>(
fn: ISetupFunction,
) {
export default function setupPage<D, AS extends AppStore>(fn: ISetupFunction) {
type View = PageInstance<D, BizPageStore> & { $setup?: PageSetup };

@@ -47,3 +45,3 @@ let view: View;

const fn = view.$setup!.getFetchInitDataMethod();
fn && await fn();
fn && (await fn());
}

@@ -60,20 +58,16 @@

options = createPage<AS, BizPageStore, D>(
BizPageStore,
options,
{
beforeCreateStore: (v: View) => {
const setup = new PageSetup();
v.$setup = setup;
view = v;
options = createPage<AS, BizPageStore, D>(BizPageStore, options, {
beforeCreateStore: (v: View) => {
const setup = new PageSetup();
v.$setup = setup;
view = v;
setup.iterateMethods((fns, name) => {
appendFn(v, name, fns);
});
},
setup.iterateMethods((fns, name) => {
appendFn(v, name, fns);
});
},
);
});
const lifeCycleMethodsOptions = integrateLifeCycleMethods<'page'>(lifeCycleMethods);
lifeCycleMethods.forEach((m) => {
lifeCycleMethods.forEach(m => {
attachLogic(options, m, 'after', lifeCycleMethodsOptions[m] as any);

@@ -80,0 +74,0 @@ });

@@ -6,6 +6,3 @@ import checkSetupEnv from './checkSetupEnv';

export default function useAppLifeCycle<F extends keyof tinyapp.IAppOptionsMethods>(
name: F,
fn: AppFullMethods[F],
) {
export default function useAppLifeCycle<F extends keyof tinyapp.IAppOptionsMethods>(name: F, fn: AppFullMethods[F]) {
checkSetupEnv('useAppLifeCycle', ['app']);

@@ -12,0 +9,0 @@

@@ -6,6 +6,3 @@ import ComponentSetup from './setup/ComponentSetup';

export default function useComponentLifeCycle<F extends (keyof FullMethods)>(
name: F,
fn: FullMethods[F],
) {
export default function useComponentLifeCycle<F extends keyof FullMethods>(name: F, fn: FullMethods[F]) {
checkSetupEnv('useComponentLifeCycle', ['component']);

@@ -12,0 +9,0 @@

@@ -7,6 +7,3 @@ import CommonSetup from './setup/CommonSetup';

export default function useFetchInitData(
fn: () => Promise<void>,
isAsync = true,
) {
export default function useFetchInitData(fn: () => Promise<void>, isAsync = true) {
checkSetupEnv('useFetchInitData', ['page', 'app', 'component']);

@@ -13,0 +10,0 @@

import PageSetup from './setup/PageSetup';
import checkSetupEnv from './checkSetupEnv';
export default function usePageEvents<F extends (keyof tinyapp.IPageEvents)>(
name: F,
fn: tinyapp.IPageEvents[F],
) {
export default function usePageEvents<F extends keyof tinyapp.IPageEvents>(name: F, fn: tinyapp.IPageEvents[F]) {
checkSetupEnv('usePageLifeCycle', ['page']);

@@ -9,0 +6,0 @@

@@ -6,6 +6,3 @@ import PageSetup from './setup/PageSetup';

export default function usePageLifeCycle<F extends (keyof FullMethods)>(
name: F,
fn: FullMethods[F],
) {
export default function usePageLifeCycle<F extends keyof FullMethods>(name: F, fn: FullMethods[F]) {
checkSetupEnv('usePageLifeCycle', ['page']);

@@ -12,0 +9,0 @@

import { AppStore } from '@goldfishjs/core';
import checkSetupEnv from './checkSetupEnv';
import {
Plugin,
RoutePlugin,
FeedbackPlugin,
BridgePlugin,
RequesterPlugin,
PluginClass,
} from '@goldfishjs/plugins';
import { Plugin, RoutePlugin, FeedbackPlugin, BridgePlugin, RequesterPlugin, PluginClass } from '@goldfishjs/plugins';
import getAppStore from './getAppStore';

@@ -19,23 +12,9 @@

};
export default function usePlugins<
A extends PluginClass,
>(
list: [A],
): Record<A['type'], InstanceType<A>>;
export default function usePlugins<
A extends PluginClass,
B extends PluginClass,
>(
export default function usePlugins<A extends PluginClass>(list: [A]): Record<A['type'], InstanceType<A>>;
export default function usePlugins<A extends PluginClass, B extends PluginClass>(
list: [A, B],
): Record<A['type'], InstanceType<A>> &
Record<B['type'], InstanceType<B>>;
export default function usePlugins<
A extends PluginClass,
B extends PluginClass,
C extends PluginClass,
>(
): Record<A['type'], InstanceType<A>> & Record<B['type'], InstanceType<B>>;
export default function usePlugins<A extends PluginClass, B extends PluginClass, C extends PluginClass>(
list: [A, B, C],
): Record<A['type'], InstanceType<A>> &
Record<B['type'], InstanceType<B>> &
Record<C['type'], InstanceType<C>>;
): Record<A['type'], InstanceType<A>> & Record<B['type'], InstanceType<B>> & Record<C['type'], InstanceType<C>>;
export default function usePlugins<

@@ -45,3 +24,3 @@ A extends PluginClass,

C extends PluginClass,
D extends PluginClass,
D extends PluginClass
>(

@@ -58,3 +37,3 @@ list: [A, B, C, D],

D extends PluginClass,
E extends PluginClass,
E extends PluginClass
>(

@@ -73,3 +52,3 @@ list: [A, B, C, D, E],

E extends PluginClass,
F extends PluginClass,
F extends PluginClass
>(

@@ -90,3 +69,3 @@ list: [A, B, C, D, E, F],

F extends PluginClass,
G extends PluginClass,
G extends PluginClass
>(

@@ -109,3 +88,3 @@ list: [A, B, C, D, E, F, G],

G extends PluginClass,
H extends PluginClass,
H extends PluginClass
>(

@@ -122,5 +101,3 @@ list: [A, B, C, D, E, F, G, H],

export default function usePlugins(list: PluginClass<Plugin>[]): Record<string, Plugin>;
export default function usePlugins(
pluginClassList?: PluginClass[],
): Record<string, Plugin> {
export default function usePlugins(pluginClassList?: PluginClass[]): Record<string, Plugin> {
checkSetupEnv('usePlugins', ['page', 'app', 'component']);

@@ -146,11 +123,8 @@ const appStore: AppStore = getAppStore();

return pluginClassList.reduce(
(prev, pluginClass) => {
Object.defineProperty(prev, pluginClass.type, {
get: () => appStore.getPluginInstance(pluginClass),
});
return prev;
},
{} as Record<string, Plugin>,
);
return pluginClassList.reduce((prev, pluginClass) => {
Object.defineProperty(prev, pluginClass.type, {
get: () => appStore.getPluginInstance(pluginClass),
});
return prev;
}, {} as Record<string, Plugin>);
}

@@ -19,4 +19,3 @@ import useContextType from './useContextType';

if (type === 'page') {
const store =
CommonSetup.getCurrent<PageSetup>().getStoreInstance()!;
const store = CommonSetup.getCurrent<PageSetup>().getStoreInstance()!;
return store.watch.bind(store);

@@ -26,4 +25,3 @@ }

if (type === 'component') {
const store =
CommonSetup.getCurrent<ComponentSetup>().getStoreInstance()!;
const store = CommonSetup.getCurrent<ComponentSetup>().getStoreInstance()!;
return store.watch.bind(store);

@@ -30,0 +28,0 @@ }

/// <reference types="mini-types" />
declare type FullMethods = Required<tinyapp.IComponentLifeCycleMethods<any, any>>;
export default function useComponentLifeCycle<F extends (keyof FullMethods)>(name: F, fn: FullMethods[F]): void;
export default function useComponentLifeCycle<F extends keyof FullMethods>(name: F, fn: FullMethods[F]): void;
export {};
/// <reference types="mini-types" />
export default function usePageEvents<F extends (keyof tinyapp.IPageEvents)>(name: F, fn: tinyapp.IPageEvents[F]): void;
export default function usePageEvents<F extends keyof tinyapp.IPageEvents>(name: F, fn: tinyapp.IPageEvents[F]): void;
/// <reference types="mini-types" />
declare type FullMethods = Required<tinyapp.IPageOptionsMethods>;
export default function usePageLifeCycle<F extends (keyof FullMethods)>(name: F, fn: FullMethods[F]): void;
export default function usePageLifeCycle<F extends keyof FullMethods>(name: F, fn: FullMethods[F]): void;
export {};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc