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

@goldfishjs/core

Package Overview
Dependencies
Maintainers
2
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@goldfishjs/core - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

8

CHANGELOG.md

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

# [1.8.0](https://github.com/alipay/goldfish/compare/v1.7.0...v1.8.0) (2021-10-22)
**Note:** Version bump only for package @goldfishjs/core
# [1.7.0](https://github.com/alipay/goldfish/compare/v1.6.1...v1.7.0) (2021-09-27)

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

59

lib/store/AppStore.d.ts

@@ -1,4 +0,2 @@

/// <reference types="mini-types" />
import { AppStore as BaseAppStore } from '@goldfishjs/reactive-connect';
import { PluginHub, PluginClass, IConfig, Plugin } from '@goldfishjs/plugins';
/**

@@ -8,18 +6,2 @@ * State management for App.

export default class AppStore extends BaseAppStore {
/**
* The plugins manager.
*
* @protected
* @type {PluginHub}
* @memberof AppStore
*/
protected pluginHub: PluginHub;
/**
* Store the configuration data.
*
* @protected
* @type {IConfig}
* @memberof AppStore
*/
protected config?: IConfig;
protected stopWatchFeedbackQueue: (() => void) | undefined;

@@ -35,29 +17,2 @@ /**

/**
* Set the config immediately after the AppStore is created.
*
* @param config
*/
setConfig(config: IConfig): void;
/**
* Get the plugins to register in the init process.
* In the Subclass, users can override this method to provide your own plugins.
*/
protected getPlugins(): PluginClass[];
/**
* Initialize the AppStore.
*
* @lifecycle
*/
init(): void;
/**
* Get the specified plugin instance.
*
* @param pluginClass
*/
getPluginInstance<R extends Plugin>(pluginClass: PluginClass<R> | string): R;
/**
* Wait for the registered plugins ready.
*/
waitForPluginsReady(): Promise<void>;
/**
* Wait for the init data finish loading.

@@ -67,6 +22,2 @@ */

/**
* Wait for all init processes ready.
*/
waitForReady(): Promise<[void, void]>;
/**
* Destroy the AppStore.

@@ -77,12 +28,2 @@ *

destroy(): void;
private startWatchFeedbackQueue;
/**
* Initialize the global feedback module.
* It is used to manage the global toasts, alerts, prompts and confirms.
*/
initFeedback(): Promise<void>;
/**
* Update Pages for Route. Only for inner usages.
*/
updatePages(page: tinyapp.IAppLaunchOptions): void;
}

370

lib/store/AppStore.js
import _observable from "@goldfishjs/reactive-connect/lib/decorators/observable";
import _state from "@goldfishjs/reactive-connect/lib/decorators/state";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncForEach from "@goldfishjs/utils/lib/asyncForEach";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _RequesterPlugin from "@goldfishjs/plugins/lib/RequesterPlugin";
import _MockRequesterPlugin from "@goldfishjs/plugins/lib/MockRequesterPlugin";
import _BridgePlugin from "@goldfishjs/plugins/lib/BridgePlugin";
import _MockBridgePlugin from "@goldfishjs/plugins/lib/MockBridgePlugin";
import _FeedbackPlugin from "@goldfishjs/plugins/lib/FeedbackPlugin";
import _RoutePlugin from "@goldfishjs/plugins/lib/RoutePlugin";
import _ConfigPlugin from "@goldfishjs/plugins/lib/ConfigPlugin";
import _PluginHub from "@goldfishjs/plugins/lib/PluginHub";
import _AppStore from "@goldfishjs/reactive-connect/lib/AppStore";

@@ -26,6 +14,2 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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); }; }

@@ -64,6 +48,2 @@

_defineProperty(_assertThisInitialized(_this), "pluginHub", new _PluginHub());
_defineProperty(_assertThisInitialized(_this), "config", void 0);
_defineProperty(_assertThisInitialized(_this), "stopWatchFeedbackQueue", void 0);

@@ -77,90 +57,13 @@

_createClass(AppStore, [{
key: "setConfig",
key: "waitForInitDataReady",
value:
/**
* Set the config immediately after the AppStore is created.
*
* @param config
* Wait for the init data finish loading.
*/
function setConfig(config) {
if (this.config) {
throw new Error('The config has bean initialized.');
}
this.config = config;
}
/**
* Get the plugins to register in the init process.
* In the Subclass, users can override this method to provide your own plugins.
*/
}, {
key: "getPlugins",
value: function getPlugins() {
return [_ConfigPlugin, _RoutePlugin, _FeedbackPlugin, process.env.NODE_ENV === 'development' ? _MockBridgePlugin : _BridgePlugin, process.env.NODE_ENV === 'development' ? _MockRequesterPlugin : _RequesterPlugin];
}
/**
* Initialize the AppStore.
*
* @lifecycle
*/
}, {
key: "init",
value: function init() {
function waitForInitDataReady() {
var _this2 = this;
_get(_getPrototypeOf(AppStore.prototype), "init", this).call(this);
var plugins = this.getPlugins();
plugins.forEach(function (plugin) {
return _this2.pluginHub.register(plugin);
}); // Pass the config to the ConfigPlugin for the later other plugins to use.
if (!this.config) {
throw new Error('Please pass in the App config.');
}
this.pluginHub.get(_ConfigPlugin).setConfig(this.config); // Initialize all plugins.
this.pluginHub.init().catch(function (e) {
// The Alipay does not catch the exception in Promise,
// so print the error here for debug.
console.error(e);
_this2.globalErrorInPromise = e;
throw e;
});
}
/**
* Get the specified plugin instance.
*
* @param pluginClass
*/
}, {
key: "getPluginInstance",
value: function getPluginInstance(pluginClass) {
return this.pluginHub.get(pluginClass);
}
/**
* Wait for the registered plugins ready.
*/
}, {
key: "waitForPluginsReady",
value: function waitForPluginsReady() {
return this.pluginHub.waitForReady();
}
/**
* Wait for the init data finish loading.
*/
}, {
key: "waitForInitDataReady",
value: function waitForInitDataReady() {
var _this3 = this;
return new Promise(function (resolve) {
var stop = _this3.watch(function () {
return _this3.isInitLoading;
var stop = _this2.watch(function () {
return _this2.isInitLoading;
}, function (newVal) {

@@ -177,11 +80,2 @@ if (!newVal) {

/**
* Wait for all init processes ready.
*/
}, {
key: "waitForReady",
value: function waitForReady() {
return Promise.all([this.waitForInitDataReady(), this.waitForPluginsReady()]);
}
/**
* Destroy the AppStore.

@@ -196,257 +90,3 @@ *

_get(_getPrototypeOf(AppStore.prototype), "destroy", this).call(this);
this.pluginHub.destroy();
}
}, {
key: "startWatchFeedbackQueue",
value: function startWatchFeedbackQueue(options) {
var _this4 = this;
var feedback = this.pluginHub.get(_FeedbackPlugin);
if (!feedback) {
throw new Error('No feedback.');
}
if (this.stopWatchFeedbackQueue) {
return this.stopWatchFeedbackQueue;
}
var isFeedbackConsuming = false;
var shouldStopIteration = false;
var stop = this.watch(function () {
return feedback.feedbackQueue;
}, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
var queue;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (!isFeedbackConsuming) {
_context2.next = 2;
break;
}
return _context2.abrupt("return");
case 2:
isFeedbackConsuming = true;
queue = _toConsumableArray(feedback.feedbackQueue);
_context2.next = 6;
return _asyncForEach(queue, /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(item) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!shouldStopIteration) {
_context.next = 2;
break;
}
return _context.abrupt("return", true);
case 2:
_context.t0 = item.popType;
_context.next = _context.t0 === 'toast' ? 5 : _context.t0 === 'alert' ? 8 : _context.t0 === 'confirm' ? 11 : _context.t0 === 'prompt' ? 14 : 17;
break;
case 5:
_context.next = 7;
return options.showToast && options.showToast(item);
case 7:
return _context.abrupt("break", 17);
case 8:
_context.next = 10;
return options.alert && options.alert(item);
case 10:
return _context.abrupt("break", 17);
case 11:
_context.next = 13;
return options.confirm && options.confirm(item);
case 13:
return _context.abrupt("break", 17);
case 14:
_context.next = 16;
return options.prompt && options.prompt(item);
case 16:
return _context.abrupt("break", 17);
case 17:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}());
case 6:
isFeedbackConsuming = false;
if (feedback.feedbackQueue.length && queue.length) {
feedback.feedbackQueue.splice(0, queue.length);
}
case 8:
case "end":
return _context2.stop();
}
}
}, _callee2);
})), {
immediate: true
});
this.stopWatchFeedbackQueue = function () {
stop();
_this4.stopWatchFeedbackQueue = undefined;
shouldStopIteration = true;
};
return this.stopWatchFeedbackQueue;
}
/**
* Initialize the global feedback module.
* It is used to manage the global toasts, alerts, prompts and confirms.
*/
}, {
key: "initFeedback",
value: function () {
var _initFeedback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
var bridge;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return this.waitForPluginsReady();
case 2:
bridge = this.getPluginInstance(_BridgePlugin);
this.startWatchFeedbackQueue({
showToast: function showToast(item) {
return new Promise(function (resolve) {
bridge.call('showToast', item);
if (item.isBlock || item.duration) {
if (item.duration) {
setTimeout(function () {
return resolve();
}, item.duration);
} else {
resolve();
bridge.call('hideToast');
}
} else {
bridge.call('hideToast');
resolve();
}
});
},
alert: function alert(item) {
return new Promise(function (resolve) {
if (item.isBlock) {
bridge.call('alert', _objectSpread(_objectSpread({}, item), {}, {
complete: function complete() {
resolve();
if (item.complete) {
item.complete();
}
}
}));
} else {
bridge.call('alert', item);
resolve();
}
});
},
confirm: function confirm(item) {
return new Promise(function (resolve) {
bridge.call('confirm', _objectSpread(_objectSpread({}, item), {}, {
confirmButtonText: item.okButtonText,
complete: function complete(result) {
if (item.isBlock) {
resolve();
}
if (item.complete) {
item.complete(result.confirm ? {
ok: true,
cancel: false
} : {
ok: false,
cancel: true
});
}
}
}));
if (!item.isBlock) {
resolve();
}
});
},
prompt: function prompt(item) {
return new Promise(function (resolve) {
bridge.call('prompt', _objectSpread(_objectSpread({}, item), {}, {
message: item.content || 'prompt',
success: function success(result) {
item.complete && item.complete(result.ok ? {
ok: true,
cancel: false,
inputValue: result.inputValue
} : {
ok: false,
cancel: true
});
},
fail: function fail() {
item.complete && item.complete({
ok: false,
cancel: false
});
},
complete: resolve
}));
});
}
});
case 4:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
function initFeedback() {
return _initFeedback.apply(this, arguments);
}
return initFeedback;
}()
/**
* Update Pages for Route. Only for inner usages.
*/
}, {
key: "updatePages",
value: function updatePages(page) {
this.pluginHub.get(_RoutePlugin).updatePages(page);
}
}]);

@@ -453,0 +93,0 @@

/// <reference types="mini-types" />
import { AppOptions, AppInstance } from '@goldfishjs/reactive-connect';
import { IConfig } from '@goldfishjs/plugins';
import AppStore from '../store/AppStore';

@@ -8,3 +7,2 @@ /**

*
* @param config The configuration for the whole App.
* @param storeClass The AppStore.

@@ -14,5 +12,5 @@ * @param appOptions The options to configure the App.

*/
export default function createApp<G, S extends AppStore>(config: IConfig, storeClass: new () => S, appOptions?: AppOptions<G, S>, options?: {
export default function createApp<G, S extends AppStore>(storeClass: new () => S, appOptions?: AppOptions<G, S>, options?: {
beforeCreateStore?: (view: AppInstance<G, S>) => void;
afterCreateStore?: (view: AppInstance<G, S>, store: S) => void;
}): tinyapp.AppOptions<G>;

@@ -14,3 +14,2 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";

*
* @param config The configuration for the whole App.
* @param storeClass The AppStore.

@@ -20,5 +19,5 @@ * @param appOptions The options to configure the App.

*/
export default function createApp(config, storeClass) {
var appOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length > 3 ? arguments[3] : undefined;
export default function createApp(storeClass) {
var appOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = arguments.length > 2 ? arguments[2] : undefined;

@@ -33,4 +32,3 @@ _attachLogic(appOptions, 'onLaunch', 'after', /*#__PURE__*/function () {

store = this.store;
store.isInitLoading = true;
store.updatePages(options); // Call onError when there is uncaught error in Promise.
store.isInitLoading = true; // Call onError when there is uncaught error in Promise.

@@ -49,26 +47,25 @@ app = getApp();

});
_context.next = 7;
return store.waitForReady();
_context.next = 6;
return store.waitForInitDataReady();
case 7:
store.initFeedback();
_context.prev = 8;
_context.next = 11;
case 6:
_context.prev = 6;
_context.next = 9;
return store.fetchInitData();
case 11:
_context.next = 16;
case 9:
_context.next = 14;
break;
case 13:
_context.prev = 13;
_context.t0 = _context["catch"](8);
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](6);
throw _context.t0;
case 16:
_context.prev = 16;
case 14:
_context.prev = 14;
store.isInitLoading = false;
return _context.finish(16);
return _context.finish(14);
case 19:
case 17:
case "end":

@@ -78,3 +75,3 @@ return _context.stop();

}
}, _callee, this, [[8, 13, 16, 19]]);
}, _callee, this, [[6, 11, 14, 17]]);
}));

@@ -89,4 +86,2 @@

afterCreateStore: function afterCreateStore(view, store) {
store.setConfig(config);
if (options && options.afterCreateStore) {

@@ -93,0 +88,0 @@ options.afterCreateStore(view, store);

@@ -25,52 +25,40 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";

_attachLogic(componentOptions, enterKey, 'after', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
_attachLogic(componentOptions, enterKey, 'after', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var store;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context.prev = _context.next) {
case 0:
store = this.store;
store.isInitLoading = true;
_context2.next = 4;
return _silent.async( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return store.appStore.waitForReady();
_context.next = 4;
return _silent.async(function () {
return store.appStore.waitForInitDataReady();
})();
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
})))();
case 4:
_context2.prev = 4;
_context2.next = 7;
_context.prev = 4;
_context.next = 7;
return store.fetchInitData();
case 7:
_context2.next = 12;
_context.next = 12;
break;
case 9:
_context2.prev = 9;
_context2.t0 = _context2["catch"](4);
throw _context2.t0;
_context.prev = 9;
_context.t0 = _context["catch"](4);
throw _context.t0;
case 12:
_context2.prev = 12;
_context.prev = 12;
store.isInitLoading = false;
return _context2.finish(12);
return _context.finish(12);
case 15:
case "end":
return _context2.stop();
return _context.stop();
}
}
}, _callee2, this, [[4, 9, 12, 15]]);
}, _callee, this, [[4, 9, 12, 15]]);
})));

@@ -77,0 +65,0 @@

@@ -23,63 +23,42 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";

_attachLogic(pageOptions, 'onLoad', 'after', /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(query) {
var store;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
store = this.store;
store.isInitLoading = true;
_context2.next = 4;
return _silent.async( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
store.appStore.updatePages({
query: query
});
_context.next = 3;
return store.appStore.waitForReady();
_attachLogic(pageOptions, 'onLoad', 'after', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var store;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
store = this.store;
store.isInitLoading = true;
_context.next = 4;
return _silent.async(function () {
return store.appStore.waitForInitDataReady();
})();
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
})))();
case 4:
_context.prev = 4;
_context.next = 7;
return store.fetchInitData();
case 4:
_context2.prev = 4;
_context2.next = 7;
return store.fetchInitData();
case 7:
_context.next = 12;
break;
case 7:
_context2.next = 12;
break;
case 9:
_context.prev = 9;
_context.t0 = _context["catch"](4);
throw _context.t0;
case 9:
_context2.prev = 9;
_context2.t0 = _context2["catch"](4);
throw _context2.t0;
case 12:
_context.prev = 12;
store.isInitLoading = false;
return _context.finish(12);
case 12:
_context2.prev = 12;
store.isInitLoading = false;
return _context2.finish(12);
case 15:
case "end":
return _context2.stop();
}
case 15:
case "end":
return _context.stop();
}
}, _callee2, this, [[4, 9, 12, 15]]);
}));
}
}, _callee, this, [[4, 9, 12, 15]]);
})));
return function (_x) {
return _ref.apply(this, arguments);
};
}());
return _createMiniPage(storeClass, pageOptions, _objectSpread(_objectSpread({}, options), {}, {

@@ -86,0 +65,0 @@ afterCreateStore: function afterCreateStore(view, store) {

{
"name": "@goldfishjs/core",
"version": "1.7.0",
"version": "1.8.0",
"description": "goldfish",

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

"dependencies": {
"@goldfishjs/module-usage": "^1.7.0",
"@goldfishjs/plugins": "^1.7.0",
"@goldfishjs/reactive-connect": "^1.7.0",
"@goldfishjs/utils": "^1.7.0",
"@goldfishjs/module-usage": "^1.8.0",
"@goldfishjs/reactive-connect": "^1.8.0",
"@goldfishjs/utils": "^1.8.0",
"mini-types": "^0.1.3"

@@ -23,0 +22,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