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

@modern-js-reduck/plugin-effects

Package Overview
Dependencies
Maintainers
6
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@modern-js-reduck/plugin-effects - npm Package Compare versions

Comparing version 1.0.3 to 1.0.6

18

dist/js/modern/__test__/index.test.js

@@ -34,6 +34,13 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

loadThunk() {
const actions = use(todoModel)[1];
const actions = use(todoModel)[1]; // cannot get `dispatch` and `getState` params, thunk effect not work correctlly
// maybe we could only support promise effect?
return () => {
actions.load.fulfilled(['2']);
};
},
voidEffect() {
// do some effect thing, for example: localStorage.setItem('hello', 'reduck');
return 'success';
}

@@ -77,2 +84,11 @@

});
test('void effect', () => {
const store = createStore({
plugins: [plugin],
middlewares: [logger]
});
const [, actions] = store.use(todoModel);
const res = actions.voidEffect();
expect(res).toEqual('success');
});
});

5

dist/js/modern/plugin.js

@@ -30,3 +30,3 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

return null;
return value;
});

@@ -50,3 +50,4 @@ } else {

promiseTypeDelimiter: '/'
}), thunk]
}), thunk // currently thunk cannot work with reduck correctlly, maybe we can just remove this style of effects
]
});

@@ -53,0 +54,0 @@ },

@@ -1,5 +0,13 @@

import { createStore, model } from '@modern-js-reduck/store';
import logger from 'redux-logger';
import { plugin } from '..';
import handleEffect from "../utils/handleEffect";
"use strict";
var _store = require("@modern-js-reduck/store");
var _reduxLogger = _interopRequireDefault(require("redux-logger"));
var _ = require("..");
var _handleEffect = _interopRequireDefault(require("../utils/handleEffect"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
jest.setTimeout(500000);

@@ -15,14 +23,14 @@

const todosModel = model('todos').define({
const todosModel = (0, _store.model)('todos').define({
state: {},
actions: {
load: handleEffect(),
loadNs: handleEffect({
load: (0, _handleEffect.default)(),
loadNs: (0, _handleEffect.default)({
ns: 'todos'
}),
loadNsResultAlias: handleEffect({
loadNsResultAlias: (0, _handleEffect.default)({
ns: 'todos',
result: 'data'
}),
loadAlias: handleEffect({
loadAlias: (0, _handleEffect.default)({
result: 'data',

@@ -32,22 +40,22 @@ pending: 'loading',

}),
loadOmitResultNs: handleEffect({
loadOmitResultNs: (0, _handleEffect.default)({
omitResultNamespace: true
}),
loadNsAndOmitResultNs: handleEffect({
loadNsAndOmitResultNs: (0, _handleEffect.default)({
ns: 'todos',
omitResultNamespace: true
}),
loadResultUndefined: handleEffect(),
loadOmitPending: handleEffect({
loadResultUndefined: (0, _handleEffect.default)(),
loadOmitPending: (0, _handleEffect.default)({
pending: false
}),
loadOmitResult: handleEffect({
loadOmitResult: (0, _handleEffect.default)({
result: false
}),
loadOmitError: handleEffect({
loadOmitError: (0, _handleEffect.default)({
error: false
}),
loadMergeMode: handleEffect(),
loadMergeModeObj: handleEffect(),
loadReplaceMode: handleEffect({
loadMergeMode: (0, _handleEffect.default)(),
loadMergeModeObj: (0, _handleEffect.default)(),
loadReplaceMode: (0, _handleEffect.default)({
combineMode: 'replace'

@@ -132,5 +140,5 @@ })

beforeEach(() => {
store = createStore({
plugins: [plugin],
middlewares: [logger]
store = (0, _store.createStore)({
plugins: [_.plugin],
middlewares: [_reduxLogger.default]
});

@@ -137,0 +145,0 @@ });

@@ -1,7 +0,18 @@

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
"use strict";
import { createStore, model } from '@modern-js-reduck/store';
import logger from 'redux-logger';
import { plugin } from '..';
const todoModel = model('todo').define((_, {
var _store = require("@modern-js-reduck/store");
var _reduxLogger = _interopRequireDefault(require("redux-logger"));
var _2 = require("..");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const todoModel = (0, _store.model)('todo').define((_, {
use

@@ -14,3 +25,3 @@ }) => ({

load: {
fulfilled: (state, payload) => _extends({}, state, {
fulfilled: (state, payload) => _objectSpread(_objectSpread({}, state), {}, {
items: payload

@@ -20,3 +31,3 @@ })

loadWithParams: {
fulfilled: (state, payload) => _extends({}, state, {
fulfilled: (state, payload) => _objectSpread(_objectSpread({}, state), {}, {
items: payload

@@ -36,6 +47,13 @@ })

loadThunk() {
const actions = use(todoModel)[1];
const actions = use(todoModel)[1]; // cannot get `dispatch` and `getState` params, thunk effect not work correctlly
// maybe we could only support promise effect?
return () => {
actions.load.fulfilled(['2']);
};
},
voidEffect() {
// do some effect thing, for example: localStorage.setItem('hello', 'reduck');
return 'success';
}

@@ -47,5 +65,5 @@

test('promise middleware', async () => {
const store = createStore({
plugins: [plugin],
middlewares: [logger]
const store = (0, _store.createStore)({
plugins: [_2.plugin],
middlewares: [_reduxLogger.default]
});

@@ -59,5 +77,5 @@ const [, actions] = store.use(todoModel);

test('promise middleware params', async () => {
const store = createStore({
plugins: [plugin],
middlewares: [logger]
const store = (0, _store.createStore)({
plugins: [_2.plugin],
middlewares: [_reduxLogger.default]
});

@@ -71,5 +89,5 @@ const [, actions] = store.use(todoModel);

test('thunk middleware', () => {
const store = createStore({
plugins: [plugin],
middlewares: [logger]
const store = (0, _store.createStore)({
plugins: [_2.plugin],
middlewares: [_reduxLogger.default]
});

@@ -82,2 +100,11 @@ const [, actions] = store.use(todoModel);

});
test('void effect', () => {
const store = (0, _store.createStore)({
plugins: [_2.plugin],
middlewares: [_reduxLogger.default]
});
const [, actions] = store.use(todoModel);
const res = actions.voidEffect();
expect(res).toEqual('success');
});
});

@@ -1,4 +0,27 @@

import plugin from "./plugin";
import handleEffect from "./utils/handleEffect";
export { plugin, handleEffect };
export default plugin;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
Object.defineProperty(exports, "handleEffect", {
enumerable: true,
get: function () {
return _handleEffect.default;
}
});
Object.defineProperty(exports, "plugin", {
enumerable: true,
get: function () {
return _plugin.default;
}
});
var _plugin = _interopRequireDefault(require("./plugin"));
var _handleEffect = _interopRequireDefault(require("./utils/handleEffect"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = _plugin.default;
exports.default = _default;

@@ -1,7 +0,22 @@

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
"use strict";
import { createPlugin } from '@modern-js-reduck/store';
import { createPromise } from 'redux-promise-middleware';
import thunk from 'redux-thunk';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _store = require("@modern-js-reduck/store");
var _reduxPromiseMiddleware = require("redux-promise-middleware");
var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**

@@ -30,3 +45,3 @@ * Generate dispatch action from effects definitions.

return null;
return value;
});

@@ -45,8 +60,9 @@ } else {

const plugin = createPlugin(context => ({
const plugin = (0, _store.createPlugin)(context => ({
config(storeConfig) {
return _extends({}, storeConfig, {
middlewares: [...(storeConfig.middlewares || []), createPromise({
return _objectSpread(_objectSpread({}, storeConfig), {}, {
middlewares: [...(storeConfig.middlewares || []), (0, _reduxPromiseMiddleware.createPromise)({
promiseTypeDelimiter: '/'
}), thunk]
}), _reduxThunk.default // currently thunk cannot work with reduck correctlly, maybe we can just remove this style of effects
]
});

@@ -80,2 +96,3 @@ },

}));
export default plugin;
var _default = plugin;
exports.default = _default;

@@ -1,3 +0,14 @@

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = handleEffect;
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const isObject = obj => {

@@ -12,3 +23,3 @@ return typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]';

const objectSet = (obj, paths, value, isImmutable = false) => {
const result = isImmutable ? _extends({}, obj) : obj;
const result = isImmutable ? _objectSpread({}, obj) : obj;
let _paths = paths;

@@ -24,3 +35,3 @@

} else if (isImmutable) {
acc[pathItem] = _extends({}, acc[pathItem]);
acc[pathItem] = _objectSpread({}, acc[pathItem]);
}

@@ -58,3 +69,3 @@

export default function handleEffect(config = {}) {
function handleEffect(config = {}) {
const {

@@ -108,3 +119,3 @@ ns,

} else if (isObject(newResult)) {
return _extends({}, currentResult, newResult);
return _objectSpread(_objectSpread({}, currentResult), newResult);
} else {

@@ -129,5 +140,5 @@ return newResult;

if (stateKey === 'result' && omitResultNamespace === true) {
return ns ? _extends({}, preState, {
[ns]: _extends({}, preState[ns], result)
}) : _extends({}, preState, result);
return ns ? _objectSpread(_objectSpread({}, preState), {
[ns]: _objectSpread(_objectSpread({}, preState[ns]), result)
}) : _objectSpread(_objectSpread({}, preState), result);
}

@@ -134,0 +145,0 @@

@@ -33,6 +33,13 @@ import _extends from "@babel/runtime/helpers/esm/extends";

loadThunk() {
const actions = use(todoModel)[1];
const actions = use(todoModel)[1]; // cannot get `dispatch` and `getState` params, thunk effect not work correctlly
// maybe we could only support promise effect?
return () => {
actions.load.fulfilled(['2']);
};
},
voidEffect() {
// do some effect thing, for example: localStorage.setItem('hello', 'reduck');
return 'success';
}

@@ -76,2 +83,11 @@

});
test('void effect', () => {
const store = createStore({
plugins: [plugin],
middlewares: [logger]
});
const [, actions] = store.use(todoModel);
const res = actions.voidEffect();
expect(res).toEqual('success');
});
});

@@ -29,3 +29,3 @@ import _extends from "@babel/runtime/helpers/esm/extends";

return null;
return value;
});

@@ -49,3 +49,4 @@ } else {

promiseTypeDelimiter: '/'
}), thunk]
}), thunk // currently thunk cannot work with reduck correctlly, maybe we can just remove this style of effects
]
});

@@ -52,0 +53,0 @@ },

@@ -13,3 +13,3 @@ import { Model } from '@modern-js-reduck/store/dist/types/types';

interface GetActions<M extends Model> {
effectsActions: M['_']['effects'] & Record<string, unknown>;
effectsActions: M['_']['effects'] & { [key in keyof M['_']['actions']]: unknown };
}

@@ -16,0 +16,0 @@ }

{
"name": "@modern-js-reduck/plugin-effects",
"version": "1.0.3",
"version": "1.0.6",
"files": [

@@ -40,3 +40,3 @@ "dist"

"devDependencies": {
"@modern-js-reduck/store": "^1.0.5",
"@modern-js-reduck/store": "1.0.6",
"@modern-js/module-tools": "^1.7.1",

@@ -46,7 +46,6 @@ "@modern-js/plugin-testing": "^1.6.0",

"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
"@types/redux-logger": "^3.0.9",
"redux-logger": "^3.0.6",
"typescript": "^4"
"typescript": "^4",
"@modern-js-reduck/scripts": "0.0.0"
},

@@ -56,3 +55,3 @@ "modernSettings": {},

"peerDependencies": {
"@modern-js-reduck/store": "^1.0.5"
"@modern-js-reduck/store": "^1.0.6"
},

@@ -68,3 +67,4 @@ "publishConfig": {

"test": "modern test"
}
},
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/api)\n\n## Contributing\n\n- [Contributing Guide](/CONTRIBUTING.md)\n"
}
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