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

@goldfishjs/reactive-connect

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/reactive-connect - npm Package Compare versions

Comparing version 1.1.17 to 1.1.18

11

lib/AppStore.js
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 Store from './Store';

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

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

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

13

lib/ComponentStore.js
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
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";
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 Store from './Store';

@@ -18,4 +13,2 @@ /* eslint-enable @typescript-eslint/no-empty-interface */

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

@@ -26,3 +19,3 @@ var _this;

_this = _super.apply(this, arguments);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ComponentStore).apply(this, arguments));
_this.isSyncDataSafe = true;

@@ -29,0 +22,0 @@ return _this;

@@ -6,11 +6,6 @@ import _markObservable from "@goldfishjs/reactive/lib/markObservable";

import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
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 STATE_KEY from './STATE_KEY';

@@ -23,5 +18,5 @@ import COMPUTED_KEY from './COMPUTED_KEY';

var _super = _createSuper(Observable);
function Observable() {
var _getPrototypeOf2;
function Observable() {
var _this;

@@ -35,3 +30,3 @@

_this = _super.call.apply(_super, [this].concat(args));
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Observable)).call.apply(_getPrototypeOf2, [this].concat(args)));
var state = {};

@@ -38,0 +33,0 @@ var computed = {};

@@ -78,5 +78,3 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

value: function set(view, fullObj, keyPathList, newV, oldV, options) {
var _a, _b;
if (((_a = options) === null || _a === void 0 ? void 0 : _a.type) === 'computed') {
if ((options === null || options === void 0 ? void 0 : options.type) === 'computed') {
newV = this.getValue(fullObj, keyPathList);

@@ -101,3 +99,3 @@ }

if (((_b = options) === null || _b === void 0 ? void 0 : _b.isArray) && options.method && isModifyArrayMethod(options.method)) {
if ((options === null || options === void 0 ? void 0 : options.isArray) && options.method && isModifyArrayMethod(options.method)) {
var optionsOldV = options.oldV || [];

@@ -104,0 +102,0 @@ updater.setSpliceObjectValue(keyPathString, newV, optionsOldV);

@@ -20,4 +20,2 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";

;
var Ancestor = function Ancestor() {

@@ -24,0 +22,0 @@ _classCallCheck(this, Ancestor);

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";
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 Store from './Store';

@@ -16,4 +11,2 @@

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

@@ -24,3 +17,3 @@ var _this;

_this = _super.apply(this, arguments);
_this = _possibleConstructorReturn(this, _getPrototypeOf(PageStore).apply(this, arguments));
_this.isSyncDataSafe = true;

@@ -27,0 +20,0 @@ return _this;

{
"name": "@goldfishjs/reactive-connect",
"version": "1.1.17",
"version": "1.1.18",
"description": "goldfish-reactive-connect",

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

"dependencies": {
"@goldfishjs/reactive": "^1.1.17",
"@goldfishjs/utils": "^1.1.17",
"@goldfishjs/reactive": "^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",
"@types/jest": "^24.0.23",
"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",
"@types/jest": "24.0.23",
"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"
},

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

@@ -1,5 +0,2 @@

export default function attachLogic<
K extends string,
F extends (...args: any[]) => any,
>(
export default function attachLogic<K extends string, F extends (...args: any[]) => any>(
options: { [N in K]?: F },

@@ -11,3 +8,3 @@ key: K,

const oldFn = options[key];
options[key] = function (this: any, ...args: any[]): any {
options[key] = function(this: any, ...args: any[]): any {
if (position === 'before') {

@@ -14,0 +11,0 @@ fn.call(this, ...args);

@@ -5,7 +5,5 @@ import { IViewInstance } from '@goldfishjs/reactive';

export type AppInstance<G, S extends AppStore> =
tinyapp.IAppInstance<G> & IViewInstance & { store?: S };
export type AppInstance<G, S extends AppStore> = tinyapp.IAppInstance<G> & IViewInstance & { store?: S };
export type AppOptions<G, S> =
ThisType<tinyapp.IAppInstance<G> & { store: S }> & tinyapp.AppOptions<G>;
export type AppOptions<G, S> = ThisType<tinyapp.IAppInstance<G> & { store: S }> & tinyapp.AppOptions<G>;

@@ -23,17 +21,12 @@ export default function createMiniApp<G, S extends AppStore>(

attachLogic<'onLaunch', Required<AppOptions<G, S>>['onLaunch']>(
appOptions,
'onLaunch',
'before',
function (
this: AppInstance<G, S>,
) {
beforeCreateStore && beforeCreateStore(this);
this.store = new storeClass();
afterCreateStore && afterCreateStore(this, this.store);
this.store.init();
},
);
attachLogic<'onLaunch', Required<AppOptions<G, S>>['onLaunch']>(appOptions, 'onLaunch', 'before', function(
this: AppInstance<G, S>,
) {
beforeCreateStore && beforeCreateStore(this);
this.store = new storeClass();
afterCreateStore && afterCreateStore(this, this.store);
this.store.init();
});
return appOptions;
}

@@ -8,7 +8,8 @@ import { connect, IViewInstance, ChangeOptions } from '@goldfishjs/reactive';

export type ComponentInstance<P, D, CS, M> =
{ store: CS } & tinyapp.IComponentInstance<P, D> & Omit<IViewInstance, 'store'> & M;
export type ComponentInstance<P, D, CS, M> = { store: CS } & tinyapp.IComponentInstance<P, D> &
Omit<IViewInstance, 'store'> &
M;
export type ComponentOptions<P, D, CS, M extends tinyapp.IComponentMethods> =
ThisType<ComponentInstance<P, D, CS, M>> & tinyapp.ComponentOptions<P, D, M>;
export type ComponentOptions<P, D, CS, M extends tinyapp.IComponentMethods> = ThisType<ComponentInstance<P, D, CS, M>> &
tinyapp.ComponentOptions<P, D, M>;

@@ -19,6 +20,6 @@ export default function createTinyappComponent<

D = any,
M extends tinyapp.IComponentMethods = tinyapp.IComponentMethods,
M extends tinyapp.IComponentMethods = tinyapp.IComponentMethods
>(
storeClass: new () => CS,
componentOptions: ComponentOptions<P, D, CS, M> & { onError?: (e: any) => void } = {},
componentOptions: ComponentOptions<P, D, CS, M> & { onError?: (e: any) => void } = {},
options?: {

@@ -38,3 +39,3 @@ beforeCreateStore?: (view: ComponentInstance<P, D, CS, M>) => void;

leaveKey,
function (
function(
this: tinyapp.IComponentInstance<P, D> & {

@@ -57,3 +58,3 @@ setData: tinyapp.SetDataMethod<D>;

},
(instance) => {
instance => {
beforeCreateStore && beforeCreateStore(instance as ComponentInstance<P, D, CS, M>);

@@ -96,3 +97,3 @@ const store = new storeClass();

'after',
function (this: ComponentInstance<P, D, CS, M>) {
function(this: ComponentInstance<P, D, CS, M>) {
this.store && (this.store.isSyncDataSafe = false);

@@ -99,0 +100,0 @@ },

@@ -7,7 +7,5 @@ import { connect, IViewInstance, ChangeOptions } from '@goldfishjs/reactive';

export type PageInstance<D, S> =
tinyapp.IPageInstance<D> & Omit<IViewInstance, 'store'> & { store: S };
export type PageInstance<D, S> = tinyapp.IPageInstance<D> & Omit<IViewInstance, 'store'> & { store: S };
export type PageOptions<D, S> =
ThisType<tinyapp.IPageInstance<D> & { store: S }> & tinyapp.PageOptions<D>;
export type PageOptions<D, S> = ThisType<tinyapp.IPageInstance<D> & { store: S }> & tinyapp.PageOptions<D>;

@@ -22,10 +20,7 @@ export default function createMiniPage<AS extends AppStore, PS extends PageStore<AS>, D = any>(

): tinyapp.PageOptions<D> {
attachLogic<'onUnload', Required<PageOptions<D, PS>>['onUnload']>(
pageOptions,
'onUnload',
'before',
function (this: PageInstance<D, PS>) {
this.store && (this.store.isSyncDataSafe = false);
},
);
attachLogic<'onUnload', Required<PageOptions<D, PS>>['onUnload']>(pageOptions, 'onUnload', 'before', function(
this: PageInstance<D, PS>,
) {
this.store && (this.store.isSyncDataSafe = false);
});

@@ -38,3 +33,3 @@ const beforeCreateStore = options && options.beforeCreateStore;

'onUnload',
function (
function(
this: tinyapp.IPageInstance<D> & {

@@ -57,3 +52,3 @@ setData: tinyapp.SetDataMethod<D>;

},
(instance) => {
instance => {
beforeCreateStore && beforeCreateStore(instance as PageInstance<D, PS>);

@@ -60,0 +55,0 @@ const store = new storeClass();

@@ -5,12 +5,4 @@ import COMPUTED_KEY from './COMPUTED_KEY';

export default function computed<T>(value: T): T;
export default function computed(
target: any,
key: string,
descriptor: TypedPropertyDescriptor<any>,
): void;
export default function computed(
target: any,
key?: string,
descriptor?: TypedPropertyDescriptor<any>,
) {
export default function computed(target: any, key: string, descriptor: TypedPropertyDescriptor<any>): void;
export default function computed(target: any, key?: string, descriptor?: TypedPropertyDescriptor<any>) {
if (!key) {

@@ -17,0 +9,0 @@ return {

@@ -23,9 +23,4 @@ import {

// 将标记好的响应式属性融合到统一的地方。
ownKeys.forEach((key) => {
if (
!(key in this[COMPUTED_KEY])
&& !(key in this[STATE_KEY])
&& this[key]
&& typeof this[key] === 'object'
) {
ownKeys.forEach(key => {
if (!(key in this[COMPUTED_KEY]) && !(key in this[STATE_KEY]) && this[key] && typeof this[key] === 'object') {
if (this[key][STATE_KEY] === 'reactive') {

@@ -32,0 +27,0 @@ markState(this, key);

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

export default function state<T>(value: T): T;
export default function state(
target: any,
key?: string,
) {
export default function state(target: any, key?: string) {
if (!key) {

@@ -18,0 +15,0 @@ return {

@@ -13,5 +13,3 @@ export default class Batch {

public async set() {
const segIndex = this.counter === 0
? this.segTotalList.length
: (this.segTotalList.length - 1);
const segIndex = this.counter === 0 ? this.segTotalList.length : this.segTotalList.length - 1;

@@ -18,0 +16,0 @@ if (!this.segTotalList[segIndex]) {

import Batch from './Batch';
import { View } from './SetTree';
import Updater from './Updater';
import {
ChangeOptions,
} from '@goldfishjs/reactive';
import { ChangeOptions } from '@goldfishjs/reactive';
import * as keyPath from './keyPath';

@@ -23,5 +21,3 @@ import { isObject } from '@goldfishjs/utils';

private getBatchUpdates(view: View) {
return view.$batchedUpdates ?
view.$batchedUpdates.bind(view) :
view.$page.$batchedUpdates.bind(view.$page);
return view.$batchedUpdates ? view.$batchedUpdates.bind(view) : view.$page.$batchedUpdates.bind(view.$page);
}

@@ -80,10 +76,3 @@

for (const k in newV) {
this.set(
view,
fullObj,
[k],
newV[k],
isObject(oldV) ? oldV[k] : undefined,
options,
);
this.set(view, fullObj, [k], newV[k], isObject(oldV) ? oldV[k] : undefined, options);
}

@@ -101,13 +90,5 @@ return;

const keyPathString = keyPath.save(keyPathList);
if (
options?.isArray
&& options.method
&& isModifyArrayMethod(options.method)
) {
if (options?.isArray && options.method && isModifyArrayMethod(options.method)) {
const optionsOldV = options.oldV || [];
updater.setSpliceObjectValue(
keyPathString,
newV,
optionsOldV,
);
updater.setSpliceObjectValue(keyPathString, newV, optionsOldV);
} else {

@@ -119,6 +100,3 @@ updater.setSetObjectValue(keyPathString, newV);

const rootKeyPathString = keyPath.save(rootKeyPathList);
updater.setSetObjectValue(
rootKeyPathString,
fullObj[rootKeyPathString],
);
updater.setSetObjectValue(rootKeyPathString, fullObj[rootKeyPathString]);
console.warn(e);

@@ -125,0 +103,0 @@ }

@@ -8,3 +8,3 @@ import { generateKeyPathString } from '@goldfishjs/reactive';

type AncestorChildren = Record<string, (Ancestor | Leaf)> | (Ancestor | Leaf)[];
type AncestorChildren = Record<string, Ancestor | Leaf> | (Ancestor | Leaf)[];

@@ -21,3 +21,3 @@ function getType(obj: any) {

return 'other';
};
}

@@ -145,5 +145,3 @@ class Ancestor {

const children = curNode.children;
const len = Array.isArray(children)
? children.length
: Object.keys(children || {}).length;
const len = Array.isArray(children) ? children.length : Object.keys(children || {}).length;
if (len > availableLeafCount) {

@@ -155,7 +153,3 @@ updateObj[generateKeyPathString(keyPathList)] = this.combine(curNode, obj);

const originObj = this.getData(obj, index);
if (
!(child instanceof Leaf)
&& index in obj
&& getType(child.children) !== getType(originObj)
) {
if (!(child instanceof Leaf) && index in obj && getType(child.children) !== getType(originObj)) {
throw new Error(`Expect the origin value is an Array, but it is: ${JSON.stringify(originObj)}.`);

@@ -166,6 +160,3 @@ }

child,
[
...keyPathList,
index,
],
[...keyPathList, index],
updateObj,

@@ -180,7 +171,3 @@ originObj,

const child = children[k];
if (
!(child instanceof Leaf)
&& k in obj
&& getType(child.children) !== getType(originObj)
) {
if (!(child instanceof Leaf) && k in obj && getType(child.children) !== getType(originObj)) {
throw new Error(`Expect the origin value is an Object, but it is: ${JSON.stringify(originObj)}.`);

@@ -191,6 +178,3 @@ }

child,
[
...keyPathList,
k,
],
[...keyPathList, k],
updateObj,

@@ -207,9 +191,3 @@ originObj,

const updateObj: Record<string, any> = {};
this.iterate(
this.root,
[],
updateObj,
obj,
this.limitLeafTotalCount.getRemainCount(),
);
this.iterate(this.root, [], updateObj, obj, this.limitLeafTotalCount.getRemainCount());
return updateObj;

@@ -216,0 +194,0 @@ }

import { cloneDeep } from '@goldfishjs/utils';
export default class SpliceTree {
private spliceObjectList: (Record<string, Parameters<Array<any>['splice']>>)[] = [];
private spliceObjectList: Record<string, Parameters<Array<any>['splice']>>[] = [];
public addNode(
keyPathString: string,
newV: any[],
oldV: any[],
) {
public addNode(keyPathString: string, newV: any[], oldV: any[]) {
if (newV.length > oldV.length) {
this.spliceObjectList.push({
[keyPathString]: [
oldV.length,
0,
...newV.slice(oldV.length, newV.length).map(item => cloneDeep(item)),
],
[keyPathString]: [oldV.length, 0, ...newV.slice(oldV.length, newV.length).map(item => cloneDeep(item))],
});
} else if (newV.length < oldV.length) {
this.spliceObjectList.push({
[keyPathString]: [
newV.length,
oldV.length - newV.length,
],
[keyPathString]: [newV.length, oldV.length - newV.length],
});

@@ -26,0 +15,0 @@ }

@@ -29,7 +29,3 @@ import SetTree from './SetTree';

public setSpliceObjectValue(
keyPathString: string,
newV: any[],
oldV: any[],
) {
public setSpliceObjectValue(keyPathString: string, newV: any[], oldV: any[]) {
let last = this.list[this.list.length - 1];

@@ -45,3 +41,3 @@ if (!last || last instanceof SetTree) {

public iterate(setCb: IterateSetCallback, spliceCb: IterateSpliceCallback) {
this.list.forEach((item) => {
this.list.forEach(item => {
if (item instanceof SetTree) {

@@ -48,0 +44,0 @@ setCb(item.generate(this.obj));

@@ -21,21 +21,15 @@ import {

function accessStoreProperties(
keys: string[],
store: Store,
) {
return keys.reduce<Record<string, any>>(
(prev, key) => {
Object.defineProperty(prev, key, {
get: () => {
return (store as any)[key];
},
set: (v: any) => {
(store as any)[key] = v;
},
enumerable: true,
});
return prev;
},
{},
);
function accessStoreProperties(keys: string[], store: Store) {
return keys.reduce<Record<string, any>>((prev, key) => {
Object.defineProperty(prev, key, {
get: () => {
return (store as any)[key];
},
set: (v: any) => {
(store as any)[key] = v;
},
enumerable: true,
});
return prev;
}, {});
}

@@ -52,6 +46,3 @@

public autorun(
fn: AutorunFunction,
errorCb?: IErrorCallback,
): UnAutorun {
public autorun(fn: AutorunFunction, errorCb?: IErrorCallback): UnAutorun {
const stop = baseAutorun(fn, errorCb);

@@ -62,7 +53,3 @@ this.stopAutorunList.push(stop);

public watch<R>(
fn: IWatchExpressionFn<R>,
cb: IWatchCallback<R>,
options?: IWatchOptions,
) {
public watch<R>(fn: IWatchExpressionFn<R>, cb: IWatchCallback<R>, options?: IWatchOptions) {
const stop = baseWatch(fn, cb, options);

@@ -69,0 +56,0 @@ this.stopWatchList.push(stop);

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