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 2.21.1 to 2.22.0-alpha.0

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [2.22.0-alpha.0](https://github.com/alipay/goldfish/compare/v2.21.1...v2.22.0-alpha.0) (2022-11-08)
**Note:** Version bump only for package @goldfishjs/composition-api
## [2.21.1](https://github.com/alipay/goldfish/compare/v2.21.1-alpha.0...v2.21.1) (2022-10-03)

@@ -8,0 +16,0 @@

7

lib/appendFn.js

@@ -5,7 +5,5 @@ export default function appendFn(options, name, fns) {

var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var result;

@@ -20,10 +18,7 @@ fns.forEach(function (fn) {

var _options$name,
_this2 = this;
_this2 = this;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
var result = (_options$name = options[name]).call.apply(_options$name, [this].concat(args));
fns.forEach(function (fn) {

@@ -30,0 +25,0 @@ result = fn.call.apply(fn, [_this2].concat(args));

@@ -5,8 +5,6 @@ /* eslint-disable react-hooks/rules-of-hooks */

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

@@ -10,14 +10,10 @@ /**

var setup = this.$setup;
if (!setup) {
return;
}
var fns = setup.getMethod(cur) || [];
var result;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
for (var i in fns) {

@@ -27,8 +23,6 @@ var fn = fns[i];

}
return result;
};
return prev;
}, {});
}

@@ -6,10 +6,7 @@ import _computed from "@goldfishjs/reactive/lib/computed";

var derive = {};
var _loop = function _loop(k) {
var descriptor = Object.getOwnPropertyDescriptor(obj, k);
if (descriptor && !descriptor.get && !descriptor.set && typeof obj[k] === 'function') {
throw new Error("Do not put function to the reactive object: ".concat(k, "."));
}
if (!descriptor || !descriptor.get && !descriptor.set) {

@@ -19,3 +16,2 @@ descriptor && Object.defineProperty(base, k, descriptor);

}
var getter = descriptor.get;

@@ -36,13 +32,8 @@ var setter = descriptor.set;

};
for (var k in obj) {
var _ret = _loop(k);
if (_ret === "continue") continue;
}
_observable(base);
_computed(derive);
for (var _k in derive) {

@@ -52,4 +43,3 @@ var desc = Object.getOwnPropertyDescriptor(derive, _k);

}
return base;
}

@@ -9,34 +9,20 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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 { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import CommonSetup from './CommonSetup';
var AppSetup = /*#__PURE__*/function (_CommonSetup) {
_inherits(AppSetup, _CommonSetup);
var _super = _createSuper(AppSetup);
function AppSetup() {
var _this;
_classCallCheck(this, AppSetup);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "launchOptions", void 0);
return _this;
}
_createClass(AppSetup, [{

@@ -47,6 +33,4 @@ key: "addMethod",

var view = this.getViewInstance();
if (view) {
var oldOnShareAppMessage = view.onShareAppMessage;
view.onShareAppMessage = function (options) {

@@ -56,7 +40,5 @@ var previousResult = oldOnShareAppMessage === null || oldOnShareAppMessage === void 0 ? void 0 : oldOnShareAppMessage.call(view, options);

};
return;
}
}
return _get(_getPrototypeOf(AppSetup.prototype), "addMethod", this).call(this, name, fn);

@@ -68,10 +50,7 @@ }

_get(_getPrototypeOf(AppSetup.prototype), "destroy", this).call(this);
this.launchOptions = undefined;
}
}]);
return AppSetup;
}(CommonSetup);
export { AppSetup as default };

@@ -13,55 +13,31 @@ import _getMiniDataSetter from "@goldfishjs/reactive-connect/lib/getMiniDataSetter";

import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import _regeneratorRuntime from "@babel/runtime/regenerator";
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 { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import Setup from './Setup';
import reactive from '../reactive';
var CommonSetup = /*#__PURE__*/function (_Setup) {
_inherits(CommonSetup, _Setup);
var _super = _createSuper(CommonSetup);
function CommonSetup() {
var _this;
_classCallCheck(this, CommonSetup);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "fetchInitDataMethod", void 0);
_defineProperty(_assertThisInitialized(_this), "viewInstance", void 0);
_defineProperty(_assertThisInitialized(_this), "methods", {});
_defineProperty(_assertThisInitialized(_this), "instanceMethods", {});
_defineProperty(_assertThisInitialized(_this), "_status", 'initializing');
_defineProperty(_assertThisInitialized(_this), "syncFnInInitializingStage", []);
_defineProperty(_assertThisInitialized(_this), "stopWatchDeepList", []);
_defineProperty(_assertThisInitialized(_this), "compositionState", {});
_defineProperty(_assertThisInitialized(_this), "stopWatchList", []);
_defineProperty(_assertThisInitialized(_this), "stopAutorunList", []);
return _this;
}
_createClass(CommonSetup, [{

@@ -83,3 +59,2 @@ key: "status",

var stop = _autorun(fn, errorCb);
this.stopAutorunList.push(stop);

@@ -92,3 +67,2 @@ return stop;

var stop = _watch(fn, cb, options);
this.stopWatchList.push(stop);

@@ -112,3 +86,2 @@ return stop;

var fetchInitDataMethod = this.fetchInitDataMethod;
if (fetchInitDataMethod) {

@@ -122,3 +95,2 @@ this.fetchInitDataMethod = isAsync ? /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {

return Promise.all([fetchInitDataMethod.call(this), fn.call(this)]);
case 2:

@@ -137,7 +109,5 @@ case "end":

return fetchInitDataMethod.call(this);
case 2:
_context2.next = 4;
return fn.call(this);
case 4:

@@ -182,3 +152,2 @@ case "end":

var onShareAppMessageFns = this.getInstanceMethod('onShareAppMessage');
if (!onShareAppMessageFns || !onShareAppMessageFns.length) {

@@ -188,3 +157,2 @@ this.add(this.instanceMethods, name, fn);

var oldOnShareAppMessage = onShareAppMessageFns[onShareAppMessageFns.length - 1];
onShareAppMessageFns[onShareAppMessageFns.length - 1] = function (options) {

@@ -216,3 +184,2 @@ var previousResult = oldOnShareAppMessage.call(this, options);

var _this2 = this;
this.wrap(function () {

@@ -222,3 +189,2 @@ if (!fn) {

}
var config = {};

@@ -229,6 +195,4 @@ config = fn();

};
var _loop = function _loop(k) {
var value = config[k];
if (typeof value === 'function') {

@@ -249,8 +213,6 @@ _this2.addInstanceMethod(k, value);

};
for (var k in config) {
_loop(k);
} // Convert the returned data to reactive one.
}
// Convert the returned data to reactive one.
var reactiveCompositionState = reactive(compositionState);

@@ -265,7 +227,5 @@ _this2.compositionState = reactiveCompositionState;

var result;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
for (var i in fns) {

@@ -275,3 +235,2 @@ var fn = fns[i];

}
return result;

@@ -283,5 +242,3 @@ }

var _this3 = this;
var compositionState = this.compositionState;
if (compositionState) {

@@ -291,3 +248,2 @@ var stopList = [];

var miniDataSetter = _getMiniDataSetter();
if (_this3.status === 'initializing') {

@@ -329,6 +285,4 @@ _this3.syncFnInInitializingStage.push(function () {

}]);
return CommonSetup;
}(Setup);
export { CommonSetup as default };

@@ -9,30 +9,18 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import CommonSetup from './CommonSetup';
var ComponentSetup = /*#__PURE__*/function (_CommonSetup) {
_inherits(ComponentSetup, _CommonSetup);
var _super = _createSuper(ComponentSetup);
function ComponentSetup() {
var _this;
_classCallCheck(this, ComponentSetup);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "props", {});
return _this;
}
_createClass(ComponentSetup, [{

@@ -51,10 +39,7 @@ key: "syncProps",

_get(_getPrototypeOf(ComponentSetup.prototype), "destroy", this).call(this);
this.props = {};
}
}]);
return ComponentSetup;
}(CommonSetup);
export { ComponentSetup as default };

@@ -6,3 +6,2 @@ var stack = [];

}
return stack[stack.length - 1];

@@ -12,3 +11,2 @@ }

stack.push(globalCache);
try {

@@ -15,0 +13,0 @@ return fn();

@@ -9,35 +9,22 @@ import _observable from "@goldfishjs/reactive/lib/observable";

import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import CommonSetup from './CommonSetup';
var PageSetup = /*#__PURE__*/function (_CommonSetup) {
_inherits(PageSetup, _CommonSetup);
var _super = _createSuper(PageSetup);
function PageSetup() {
var _this;
_classCallCheck(this, PageSetup);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "query", _observable({
data: undefined
}));
return _this;
}
return _createClass(PageSetup);
}(CommonSetup);
export { PageSetup as default };

@@ -15,10 +15,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

*/
var Setup = /*#__PURE__*/function () {
function Setup() {
_classCallCheck(this, Setup);
_defineProperty(this, "state", 'READY');
}
_createClass(Setup, [{

@@ -37,7 +34,5 @@ key: "add",

throw new Error("Wrong setup state while calling 'add' method: ".concat(this.state, "."));
} // Support recording multiple things in one key.
}
// Support recording multiple things in one key.
var item = map[name];
if (item) {

@@ -52,3 +47,2 @@ item.push(val);

*/
}, {

@@ -60,3 +54,2 @@ key: "start",

}
this.state = 'START';

@@ -67,3 +60,2 @@ }

*/
}, {

@@ -79,3 +71,2 @@ key: "clear",

*/
}, {

@@ -86,5 +77,3 @@ key: "wrap",

this.start();
var result = _wrap(this, setupFn);
return result;

@@ -107,6 +96,4 @@ } catch (e) {

}]);
return Setup;
}();
export { Setup as default };
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var Manager = /*#__PURE__*/function () {
function Manager() {
_classCallCheck(this, Manager);
_defineProperty(this, "map", {});
}
_createClass(Manager, [{

@@ -32,6 +29,4 @@ key: "add",

}]);
return Manager;
}();
export default new Manager();

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

import _uniqueId from "@goldfishjs/utils/lib/uniqueId";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import { get as keyPathGet } from '@goldfishjs/reactive-connect/lib/MiniDataSetter/keyPath';

@@ -21,38 +18,31 @@ import AppSetup from './setup/AppSetup';

var options = {};
var finalData = {}; // Create the setup instance.
var finalData = {};
// Create the setup instance.
var setup = new AppSetup();
var appSetupId = _uniqueId('app-setup-');
finalData[APP_SETUP_ID_KEY] = appSetupId;
setupManager.add(appSetupId, setup); // Execute the setup function.
setup.executeSetupFunction(fn); // Set the global data.
setupManager.add(appSetupId, setup);
// Execute the setup function.
setup.executeSetupFunction(fn);
// Set the global data.
var compositionData = setup.compositionState;
if (compositionData) {
finalData = _typeof(finalData) === 'object' ? _objectSpread(_objectSpread({}, finalData), _cloneDeep(compositionData)) : _cloneDeep(compositionData);
}
options.globalData = finalData;
_attachLogic(options, 'onLaunch', 'before', function (options) {
var _this = this;
setup.status = 'ready'; // Save the launch options.
setup.launchOptions = options; // Set the app instance.
setup.setViewInstance(this); // Mount the instance methods.
setup.status = 'ready';
// Save the launch options.
setup.launchOptions = options;
// Set the app instance.
setup.setViewInstance(this);
// Mount the instance methods.
setup.iterateInstanceMethods(function (fns, name) {
appendFn(_this, name, fns);
}); // Watch the reactive data.
});
// Watch the reactive data.
this.$batchedUpdates = function (cb) {
return cb();
};
this.setData = function (obj) {

@@ -65,7 +55,5 @@ var _loop = function _loop(key) {

}
return prevData[keySeg];
}, _this.globalData);
};
for (var key in obj) {

@@ -75,3 +63,2 @@ _loop(key);

};
this.$spliceData = function (obj) {

@@ -83,10 +70,7 @@ var _loop2 = function _loop2(key) {

var _prevData$keySeg;
(_prevData$keySeg = prevData[keySeg]).splice.apply(_prevData$keySeg, [obj[key][0], obj[key][1]].concat(_toConsumableArray(obj[key].slice(2))));
}
return prevData[keySeg];
}, _this.globalData);
};
for (var key in obj) {

@@ -96,15 +80,11 @@ _loop2(key);

};
setup.watchReactiveData(); // Init loading
setup.watchReactiveData();
// Init loading
var initFn = setup.getFetchInitDataMethod();
var initCompleteHandler = function initCompleteHandler() {
setup.compositionState.isInitLoading = false;
};
Promise.resolve(initFn && initFn()).then(initCompleteHandler, initCompleteHandler);
}); // Mount the lifecycle methods.
});
// Mount the lifecycle methods.
function integrateLifeCycleMethods(lifeCycleMethods) {

@@ -116,10 +96,7 @@ return lifeCycleMethods.reduce(function (prev, cur) {

}
return setup.executeLifeCycleFns.apply(setup, [cur].concat(args));
};
return prev;
}, {});
}
var lifeCycleMethodsOptions = integrateLifeCycleMethods(lifeCycleMethods);

@@ -126,0 +103,0 @@ lifeCycleMethods.forEach(function (m) {

@@ -6,7 +6,4 @@ import _attachLogic from "@goldfishjs/reactive-connect/lib/attachLogic";

import _uniqueId from "@goldfishjs/utils/lib/uniqueId";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import observable from '@goldfishjs/reactive/lib/observable';

@@ -23,3 +20,2 @@ import isComponent2 from '@goldfishjs/reactive-connect/lib/isComponent2';

var fn = undefined;
if (typeof arg1 === 'function') {

@@ -31,38 +27,29 @@ fn = arg1;

}
var options = {};
if (props) {
options.props = props;
}
var oldData = options.data; // No `this` for the component data function.
var oldData = options.data;
// No `this` for the component data function.
options.data = function () {
var finalData = {};
if (oldData) {
finalData = typeof oldData === 'function' ? oldData() : oldData;
} // Create the setup instance.
}
// Create the setup instance.
var componentSetupId = _uniqueId('component-setup-');
finalData[COMPONENT_SETUP_ID_KEY] = componentSetupId;
var setup = new ComponentSetup();
setupManager.add(componentSetupId, setup); // Get the default props.
setup.props = observable(_cloneDeep(props) || {}); // Execute the setup function.
setupManager.add(componentSetupId, setup);
// Get the default props.
setup.props = observable(_cloneDeep(props) || {});
// Execute the setup function.
setup.executeSetupFunction(fn);
var compositionData = setup.compositionState;
if (compositionData) {
finalData = _typeof(finalData) === 'object' ? _objectSpread(_objectSpread({}, finalData), _cloneDeep(compositionData)) : _cloneDeep(compositionData);
}
return finalData;
}; // Sync props in lifecyle.
};
// Sync props in lifecyle.
function defaultSyncHandler() {

@@ -72,35 +59,27 @@ var setup = setupManager.get(this.data[COMPONENT_SETUP_ID_KEY]);

}
var enterKey = isComponent2Param ? 'onInit' : 'didMount';
_attachLogic(options, enterKey, 'before', function () {
var _this = this;
var setup = setupManager.get(this.data[COMPONENT_SETUP_ID_KEY]);
if (!setup) {
return;
}
setup.status = 'ready'; // Set the component instance.
setup.setViewInstance(this); // Mount the instance methods.
setup.status = 'ready';
// Set the component instance.
setup.setViewInstance(this);
// Mount the instance methods.
setup.iterateInstanceMethods(function (fns, name) {
appendFn(_this, name, fns);
}); // Watch the reactive data.
setup.watchReactiveData(); // Ensure the sync logic after the `watchReactiveData`.
});
// Watch the reactive data.
setup.watchReactiveData();
// Ensure the sync logic after the `watchReactiveData`.
defaultSyncHandler.call(this);
});
_attachLogic(options, 'didUpdate', 'before', defaultSyncHandler);
_attachLogic(options, 'deriveDataFromProps', 'before', function (nextProps) {
var setup = setupManager.get(this.data[COMPONENT_SETUP_ID_KEY]);
setup === null || setup === void 0 ? void 0 : setup.syncProps(nextProps);
}); // Mount the lifecycle methods.
});
// Mount the lifecycle methods.
function integrateLifeCycleMethods(lifeCycleMethods) {

@@ -110,23 +89,18 @@ return lifeCycleMethods.reduce(function (prev, cur) {

var setup = setupManager.get(this.data[COMPONENT_SETUP_ID_KEY]);
if (!setup) {
return;
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return setup.executeLifeCycleFns.apply(setup, [cur].concat(args));
};
return prev;
}, {});
}
var lifeCycleMethodsOptions = integrateLifeCycleMethods(lifeCycleMethods);
lifeCycleMethods.forEach(function (m) {
_attachLogic(options, m, 'after', lifeCycleMethodsOptions[m]);
}); // Destroy
});
// Destroy
_attachLogic(options, 'didUnmount', 'after', function () {

@@ -136,3 +110,2 @@ var setup = setupManager.get(this.data[COMPONENT_SETUP_ID_KEY]);

});
return options;

@@ -139,0 +112,0 @@ }

@@ -6,7 +6,4 @@ import _attachLogic from "@goldfishjs/reactive-connect/lib/attachLogic";

import _uniqueId from "@goldfishjs/utils/lib/uniqueId";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import PageSetup from './setup/PageSetup';

@@ -18,3 +15,2 @@ import appendFn from './appendFn';

export var PAGE_SETUP_ID_KEY = '$$pageSetupId';
function integratePageEventMethods(pageMethods) {

@@ -24,16 +20,11 @@ return pageMethods.reduce(function (prev, cur) {

var _this$data;
var setup = setupManager.get((_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data[PAGE_SETUP_ID_KEY]);
if (!setup) {
return;
}
var fns = setup.getMethod("events.".concat(cur)) || [];
var result;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
for (var i in fns) {

@@ -43,70 +34,53 @@ var fn = fns[i];

}
return result;
};
return prev;
}, {});
}
export default function setupPage(fn) {
var options = {};
var oldData = options.data;
options.data = function () {
var _this = this;
var finalData = {};
if (oldData) {
finalData = typeof oldData === 'function' ? oldData.call(this) : oldData;
} // Create the setup instance.
}
// Create the setup instance.
var pageSetupId = _uniqueId('page-setup-');
finalData[PAGE_SETUP_ID_KEY] = pageSetupId;
var setup = new PageSetup();
setupManager.add(pageSetupId, setup); // Execute the setup function.
setupManager.add(pageSetupId, setup);
// Execute the setup function.
setup.executeSetupFunction(fn);
var compositionData = setup.compositionState;
if (compositionData) {
finalData = _typeof(finalData) === 'object' ? _objectSpread(_objectSpread({}, finalData), _cloneDeep(compositionData)) : _cloneDeep(compositionData);
} // Set the component instance.
setup.setViewInstance(this); // Mount the instance methods.
}
// Set the component instance.
setup.setViewInstance(this);
// Mount the instance methods.
setup.iterateInstanceMethods(function (fns, name) {
appendFn(_this, name, fns);
}); // Watch the reactive data.
setup.watchReactiveData(); // Init loading
});
// Watch the reactive data.
setup.watchReactiveData();
// Init loading
var initFn = setup.getFetchInitDataMethod();
var initCompleteHandler = function initCompleteHandler() {
setup.compositionState.isInitLoading = false;
};
Promise.resolve(initFn && initFn()).then(initCompleteHandler, initCompleteHandler);
return finalData;
};
_attachLogic(options, 'onLoad', 'before', function (query) {
var _this$data2;
var setup = setupManager.get((_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2[PAGE_SETUP_ID_KEY]);
if (!setup) {
return;
}
setup.status = 'ready';
setup.query.data = query;
}); // Mount the lifecycle methods.
});
// Mount the lifecycle methods.
function integrateLifeCycleMethods(lifeCycleMethods) {

@@ -116,40 +90,31 @@ return lifeCycleMethods.reduce(function (prev, cur) {

var _this$data3;
var setup = setupManager.get((_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3[PAGE_SETUP_ID_KEY]);
if (!setup) {
return;
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return setup.executeLifeCycleFns.apply(setup, [cur].concat(args));
};
return prev;
}, {});
}
var lifeCycleMethodsOptions = integrateLifeCycleMethods(lifeCycleMethods);
lifeCycleMethods.forEach(function (m) {
_attachLogic(options, m, 'after', lifeCycleMethodsOptions[m]);
}); // Mount the page event methods.
});
// Mount the page event methods.
var pageEventMethodsOptions = integratePageEventMethods(pageEventMethods);
pageEventMethods.forEach(function (m) {
options.events = options.events || {};
_attachLogic(options.events, m, 'after', pageEventMethodsOptions[m]);
}); // Destroy
});
// Destroy
_attachLogic(options, 'onUnload', 'after', function () {
var _this$data4;
var setup = setupManager.get((_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4[PAGE_SETUP_ID_KEY]);
setup === null || setup === void 0 ? void 0 : setup.destroy();
});
return options;
}

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

checkSetupEnv('useAppLifeCycle', ['app']);
var setup = AppSetup.getCurrent(); // Treat the `onShareAppMessage` to an instance member.
var setup = AppSetup.getCurrent();
// Treat the `onShareAppMessage` to an instance member.
if (name === 'onShareAppMessage') {

@@ -9,0 +9,0 @@ setup.addInstanceMethod('onShareAppMessage', fn);

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

var type = useContextType();
if (['app', 'page', 'component'].indexOf(type) > -1) {

@@ -13,4 +12,3 @@ var setup = CommonSetup.getCurrent();

}
throw new Error('Unknown context.');
}

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

var setup = PageSetup.getCurrent();
if (!setup) {
throw new Error('Can not get context type out of setup flow.');
}
if (setup instanceof PageSetup) {
return 'page';
}
if (setup instanceof ComponentSetup) {
return 'component';
}
if (setup instanceof AppSetup) {
return 'app';
}
throw new Error('Unknown context.');
}

@@ -5,4 +5,4 @@ import PageSetup from './setup/PageSetup';

checkSetupEnv('usePageLifeCycle', ['page']);
var setup = PageSetup.getCurrent(); // Treat the `onShareAppMessage` to an instance member.
var setup = PageSetup.getCurrent();
// Treat the `onShareAppMessage` to an instance member.
if (name === 'onShareAppMessage') {

@@ -9,0 +9,0 @@ setup.addInstanceMethod('onShareAppMessage', fn);

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

var type = useContextType();
if (['app', 'page', 'component'].indexOf(type) > -1) {

@@ -13,4 +12,3 @@ var setup = CommonSetup.getCurrent();

}
throw new Error('Unknown context.');
}
{
"name": "@goldfishjs/composition-api",
"version": "2.21.1",
"version": "2.22.0-alpha.0",
"description": "goldfish-composition-api",

@@ -17,6 +17,6 @@ "main": "lib/index.js",

"dependencies": {
"@goldfishjs/module-usage": "^2.21.1",
"@goldfishjs/reactive": "^2.21.1",
"@goldfishjs/reactive-connect": "^2.21.1",
"@goldfishjs/utils": "^2.21.1",
"@goldfishjs/module-usage": "^2.22.0-alpha.0",
"@goldfishjs/reactive": "^2.22.0-alpha.0",
"@goldfishjs/reactive-connect": "^2.22.0-alpha.0",
"@goldfishjs/utils": "^2.22.0-alpha.0",
"mini-types": "^0.1.7"

@@ -23,0 +23,0 @@ },

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