Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

concent-utils

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concent-utils - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

lib/concent-utils.min.js

@@ -15,2 +15,2 @@ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("concent")):"function"==typeof define&&define.amd?define(["exports","concent"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["concent-utils"]={},e.concent)}(this,(function(e,n){"use strict";

and limitations under the License.
***************************************************************************** */function t(e,n,t,r){return new(t||(t=Promise))((function(o,u){function a(e){try{i(r.next(e))}catch(e){u(e)}}function c(e){try{i(r.throw(e))}catch(e){u(e)}}function i(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,c)}i((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,o,u,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(u){return function(c){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=n.call(e,a)}catch(e){u=[6,e],r=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}e.callTarget=function(e,n){return t(this,void 0,void 0,(function(){var t,o,u,a,c,i;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,5,,6]),Array.isArray(e)?(t=e[0],u=e[1],[4,n.dispatch(t,u)]):[3,2];case 1:return r.sent(),[3,4];case 2:return o=e.fnName,u=e.payload,a=e.renderKey,c=e.delay,[4,n.dispatch(o,u,a,c)];case 3:r.sent(),r.label=4;case 4:return[3,6];case 5:return i=r.sent(),alert(i.message),[3,6];case 6:return[2]}}))}))},e.makeUseModel=function(e){return function(t){var r=t||{};return n.useConcent({module:e,props:r})}},e.makeUseModelWithSetup=function(e){return function(t,r){var o=r||{};o.cuSpec;var u=o.props,a=o.extra,c=u||{};return n.useConcent({module:e,setup:t,props:c,extra:a})}},e.makeUseModelWithSetupCuf=function(e){return function(t,r){var o=r||{};o.cuSpec;var u=o.props,a=o.extra,c=u||{};return n.useConcent({module:e,setup:t,props:c,extra:a})}},Object.defineProperty(e,"__esModule",{value:!0})}));
***************************************************************************** */function t(e,n,t,r){return new(t||(t=Promise))((function(o,u){function c(e){try{s(r.next(e))}catch(e){u(e)}}function a(e){try{s(r.throw(e))}catch(e){u(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(c,a)}s((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,o,u,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;c;)try{if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,r=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=n.call(e,c)}catch(e){u=[6,e],r=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}var o=function(){return{}};e.callTarget=function(e,n){return t(this,void 0,void 0,(function(){var t,o,u,c,a,s;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,5,,6]),Array.isArray(e)?(t=e[0],u=e[1],[4,n.dispatch(t,u)]):[3,2];case 1:return r.sent(),[3,4];case 2:return o=e.fnName,u=e.payload,c=e.renderKey,a=e.delay,[4,n.dispatch(o,u,c,a)];case 3:r.sent(),r.label=4;case 4:return[3,6];case 5:return s=r.sent(),alert(s.message),[3,6];case 6:return[2]}}))}))},e.makeUseModel=function(e){return function(t){var r=t||{};return n.useConcent({module:e,props:r})}},e.makeUseModelWithSetup=function(e){return function(t,r){var u=r||{},c=u.cuDesc,a=u.props,s=u.extra,i=u.passCuDesc,l=a||{},f=void 0===i||i?c:null,p=t||o;return n.useConcent({module:e,setup:p,props:l,extra:s,cuDesc:f})}},e.makeUseModelWithSetupCuf=function(e){return function(t,r){var u=r||{},c=u.cuDesc,a=u.props,s=u.extra,i=u.passCuDesc,l=a||{},f=void 0===i||i?c:null,p=t||o;return n.useConcent({module:e,setup:p,props:l,extra:s,cuDesc:f})}},Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -1,13 +0,55 @@

import { IRefCtxM, ModuleDesc, ReducerCallerParams, IReducerFn, IActionCtxBase, IAnyFn, ICtxBase, IAnyObj, SettingsType, ComputedValType, ComputedValTypeForFn } from 'concent';
/**
* concent 相关的一些公共封装函数
*/
import { IRefCtxM, ModuleDesc, ReducerCallerParams, IReducerFn, IActionCtxBase, ICtxBase, IAnyObj, SettingsType, ComputedValType, ComputedValTypeForFn, MultiComputedFn, MultiComputed } from 'concent';
/**
* 调用目标函数,用于对接 reducer里的 ghost函数
* @param callerParams
* @param ac
*/
export declare function callTarget(callerParams: ReducerCallerParams | [IReducerFn, any], ac: IActionCtxBase): Promise<void>;
export declare function makeUseModel<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string): <P extends IAnyObj>(props?: P | undefined) => IRefCtxM<RootInfo, P, ModelDesc, {}, {}, {}>;
export declare function makeUseModelWithSetup<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string): <Setup extends (ctx: ICtxBase) => IAnyObj, CuSpec extends IAnyObj, P extends IAnyObj, Extra extends IAnyObj>(setup: Setup, opts?: {
cuSpec?: CuSpec | undefined;
props?: P | undefined;
extra?: Extra | undefined;
} | undefined) => IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValType<CuSpec>, Extra>;
export declare function makeUseModelWithSetupCuf<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string): <Setup extends (ctx: ICtxBase) => IAnyObj, CuSpec extends IAnyFn, P extends IAnyObj, Extra extends IAnyObj>(setup: Setup, opts?: {
cuSpec?: CuSpec | undefined;
props?: P | undefined;
extra?: Extra | undefined;
} | undefined) => IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValTypeForFn<CuSpec>, Extra>;
export interface BaseOpts<P extends IAnyObj, Extra extends IAnyObj> {
props?: P;
extra?: Extra;
/**
* 是否透传 cuSpec 给 useConcent函数,默认为true,
* 表示需要透传,此时用户不需要再setup函数体内调用 ctx.computed(cuSpec)
* 如果用户设置passCuSpec为false,表示传入 cuSpec 仅为了方便推导出refComputed类型,但不透传 cuSpec 给 useConcent函数
* 注意此时用户需要在 setup函数体内调用 ctx.computed(cuSpec) 来完成示例计算函数的定义,
* 否则 refComputed 里拿不到真正的计算结果
*/
passCuDesc?: boolean;
}
export interface Opts<CuDesc extends MultiComputed, P extends IAnyObj, Extra extends IAnyObj> extends BaseOpts<P, Extra> {
/**
* 对象型计算函数描述体
* const cuDesc = {
* xxx:({num}:St)=><button>{num}</button>,
* yyy:({bigNum}:St)=><button>{bigNum}</button>,
* }
*/
cuDesc?: CuDesc;
}
export interface CufOpts<CuDesc extends MultiComputedFn, P extends IAnyObj, Extra extends IAnyObj> extends BaseOpts<P, Extra> {
/**
* 函数型计算函数描述体, 通常用于脱离了setup函数体内时,需要拿到渲染上下文句柄做一些其他事情
* 如获得 ctx.mr 去绑定onClick事件等
*
* function cuDesc(ctx:CtxPre){
* const { mr } = ctx;
* return {
* xxx:({num}:St)=><button onClick={mr.add}>{num}</button>
* }
* }
*/
cuDesc?: CuDesc;
}
export declare type ValidSetup = (ctx: ICtxBase) => IAnyObj | void;
export declare type StepParam = ValidSetup | null;
export declare function makeUseModelWithSetup<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string): <Setup extends StepParam, CuDesc extends MultiComputed, P extends IAnyObj, Extra extends IAnyObj>(setup: Setup, opts?: Opts<CuDesc, P, Extra> | undefined) => IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValType<CuDesc>, Extra>;
/**
* 函数型 cuSpec 需要用此函数来推导类型
* @param moduleName
*/
export declare function makeUseModelWithSetupCuf<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string): <Setup extends StepParam, CuDesc extends MultiComputedFn, P extends IAnyObj, Extra extends IAnyObj>(setup: Setup, opts?: CufOpts<CuDesc, P, Extra> | undefined) => IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValTypeForFn<CuDesc>, Extra>;

@@ -37,3 +37,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
/**
* concent 相关的一些公共封装函数
*/
import { useConcent, } from 'concent';
/**
* 调用目标函数,用于对接 reducer里的 ghost函数
* @param callerParams
* @param ac
*/
export function callTarget(callerParams, ac) {

@@ -46,20 +54,20 @@ return __awaiter(this, void 0, void 0, function () {

_a.trys.push([0, 5, , 6]);
if (!Array.isArray(callerParams)) return [3, 2];
if (!Array.isArray(callerParams)) return [3 /*break*/, 2];
fn = callerParams[0], payload = callerParams[1];
return [4, ac.dispatch(fn, payload)];
return [4 /*yield*/, ac.dispatch(fn, payload)];
case 1:
_a.sent();
return [3, 4];
return [3 /*break*/, 4];
case 2:
fnName = callerParams.fnName, payload = callerParams.payload, renderKey = callerParams.renderKey, delay = callerParams.delay;
return [4, ac.dispatch(fnName, payload, renderKey, delay)];
return [4 /*yield*/, ac.dispatch(fnName, payload, renderKey, delay)];
case 3:
_a.sent();
_a.label = 4;
case 4: return [3, 6];
case 4: return [3 /*break*/, 6];
case 5:
err_1 = _a.sent();
alert(err_1.message);
return [3, 6];
case 6: return [2];
return [3 /*break*/, 6];
case 6: return [2 /*return*/];
}

@@ -75,18 +83,24 @@ });

}
var noop = function () { };
var noop = function () { return ({}); };
export function makeUseModelWithSetup(moduleName) {
return function useModelWithSetup(setup, opts) {
var _a = opts || {}, cuSpec = _a.cuSpec, props = _a.props, extra = _a.extra;
var _a = opts || {}, cuDesc = _a.cuDesc, props = _a.props, extra = _a.extra, _b = _a.passCuDesc, passCuDesc = _b === void 0 ? true : _b;
var targetProps = (props || {});
noop(cuSpec);
return useConcent({ module: moduleName, setup: setup, props: targetProps, extra: extra });
var targetCuDesc = passCuDesc ? cuDesc : null;
var targetSetup = (setup || noop);
return useConcent({ module: moduleName, setup: targetSetup, props: targetProps, extra: extra, cuDesc: targetCuDesc });
};
}
/**
* 函数型 cuSpec 需要用此函数来推导类型
* @param moduleName
*/
export function makeUseModelWithSetupCuf(moduleName) {
return function useModelWithSetup(setup, opts) {
var _a = opts || {}, cuSpec = _a.cuSpec, props = _a.props, extra = _a.extra;
return function useModelWithSetupCuf(setup, opts) {
var _a = opts || {}, cuDesc = _a.cuDesc, props = _a.props, extra = _a.extra, _b = _a.passCuDesc, passCuDesc = _b === void 0 ? true : _b;
var targetProps = (props || {});
noop(cuSpec);
return useConcent({ module: moduleName, setup: setup, props: targetProps, extra: extra });
var targetCuDesc = passCuDesc ? cuDesc : null;
var targetSetup = (setup || noop);
return useConcent({ module: moduleName, setup: targetSetup, props: targetProps, extra: extra, cuDesc: targetCuDesc });
};
}

@@ -21,3 +21,3 @@ {

"@typescript-eslint/parser": "^4.7.0",
"concent": "^2.12.7",
"concent": "^2.13.3",
"eslint": "^7.12.1",

@@ -66,3 +66,3 @@ "eslint-config-prettier": "^6.15.0",

},
"version": "1.0.1"
"version": "1.0.2"
}

@@ -6,4 +6,5 @@ /**

useConcent, IRefCtxM, ModuleDesc,
ReducerCallerParams, IReducerFn, IActionCtxBase, IAnyFn,
ReducerCallerParams, IReducerFn, IActionCtxBase,
ICtxBase, IAnyObj, SettingsType, ComputedValType, ComputedValTypeForFn,
MultiComputedFn, MultiComputed,
} from 'concent';

@@ -39,13 +40,59 @@

const noop = () => { };
export interface BaseOpts<P extends IAnyObj, Extra extends IAnyObj> {
props?: P;
extra?: Extra;
/**
* 是否透传 cuSpec 给 useConcent函数,默认为true,
* 表示需要透传,此时用户不需要再setup函数体内调用 ctx.computed(cuSpec)
* 如果用户设置passCuSpec为false,表示传入 cuSpec 仅为了方便推导出refComputed类型,但不透传 cuSpec 给 useConcent函数
* 注意此时用户需要在 setup函数体内调用 ctx.computed(cuSpec) 来完成示例计算函数的定义,
* 否则 refComputed 里拿不到真正的计算结果
*/
passCuDesc?: boolean;
}
export interface Opts<CuDesc extends MultiComputed, P extends IAnyObj, Extra extends IAnyObj>
extends BaseOpts<P, Extra> {
/**
* 对象型计算函数描述体
* const cuDesc = {
* xxx:({num}:St)=><button>{num}</button>,
* yyy:({bigNum}:St)=><button>{bigNum}</button>,
* }
*/
cuDesc?: CuDesc;
}
export interface CufOpts<CuDesc extends MultiComputedFn, P extends IAnyObj, Extra extends IAnyObj>
extends BaseOpts<P, Extra> {
/**
* 函数型计算函数描述体, 通常用于脱离了setup函数体内时,需要拿到渲染上下文句柄做一些其他事情
* 如获得 ctx.mr 去绑定onClick事件等
*
* function cuDesc(ctx:CtxPre){
* const { mr } = ctx;
* return {
* xxx:({num}:St)=><button onClick={mr.add}>{num}</button>
* }
* }
*/
cuDesc?: CuDesc;
}
export type ValidSetup = (ctx: ICtxBase) => IAnyObj | void;
export type StepParam = ValidSetup | null;
const noop = () => ({});
export function makeUseModelWithSetup<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string) {
return function useModelWithSetup<
Setup extends (ctx: ICtxBase) => IAnyObj, CuSpec extends IAnyObj, P extends IAnyObj, Extra extends IAnyObj,
>(setup: Setup, opts?: { cuSpec?: CuSpec, props?: P, extra?: Extra }) {
const { cuSpec, props, extra } = opts || {};
Setup extends StepParam, CuDesc extends MultiComputed, P extends IAnyObj, Extra extends IAnyObj,
>(setup: Setup, opts?: Opts<CuDesc, P, Extra>) {
const { cuDesc, props, extra, passCuDesc = true } = opts || {};
const targetProps = (props || {}) as P;
// @ts-ignore
noop(cuSpec);// 仅用于推导出类型
type Ctx = IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValType<CuSpec>, Extra>;
return useConcent<P, Ctx>({ module: moduleName, setup, props: targetProps, extra });
const targetCuDesc = passCuDesc ? cuDesc : null;
const targetSetup = (setup || noop) as ValidSetup;
type Ctx = IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValType<CuDesc>, Extra>;
return useConcent<P, Ctx>({ module: moduleName, setup: targetSetup, props: targetProps, extra, cuDesc: targetCuDesc });
}

@@ -56,15 +103,16 @@ }

* 函数型 cuSpec 需要用此函数来推导类型
* @param moduleName
* @param moduleName
*/
export function makeUseModelWithSetupCuf<RootInfo, ModelDesc extends ModuleDesc>(moduleName: string) {
return function useModelWithSetup<
Setup extends (ctx: ICtxBase) => IAnyObj, CuSpec extends IAnyFn, P extends IAnyObj, Extra extends IAnyObj,
>(setup: Setup, opts?: { cuSpec?: CuSpec, props?: P, extra?: Extra }) {
const { cuSpec, props, extra } = opts || {};
return function useModelWithSetupCuf<
Setup extends StepParam, CuDesc extends MultiComputedFn, P extends IAnyObj, Extra extends IAnyObj,
>(setup: Setup, opts?: CufOpts<CuDesc, P, Extra>) {
const { cuDesc, props, extra, passCuDesc = true } = opts || {};
const targetProps = (props || {}) as P;
// @ts-ignore
noop(cuSpec);// 仅用于推导出类型
type Ctx = IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValTypeForFn<CuSpec>, Extra>;
return useConcent<P, Ctx>({ module: moduleName, setup, props: targetProps, extra });
const targetCuDesc = passCuDesc ? cuDesc : null;
const targetSetup = (setup || noop) as ValidSetup;
type Ctx = IRefCtxM<RootInfo, P, ModelDesc, SettingsType<Setup>, ComputedValTypeForFn<CuDesc>, Extra>;
return useConcent<P, Ctx>({ module: moduleName, setup: targetSetup, props: targetProps, extra, cuDesc: targetCuDesc });
}
}
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