-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c38e1
commit 70f3917
Showing
6 changed files
with
3,052 additions
and
1,846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,35 @@ | ||
{ | ||
"presets": ["env", "react", "stage-0"], | ||
"plugins": ["transform-runtime"] | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-runtime", | ||
"@babel/plugin-syntax-dynamic-import", | ||
"@babel/plugin-syntax-import-meta", | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-json-strings", | ||
[ | ||
"@babel/plugin-proposal-decorators", | ||
{ | ||
"legacy": true | ||
} | ||
], | ||
"@babel/plugin-proposal-function-sent", | ||
"@babel/plugin-proposal-export-namespace-from", | ||
"@babel/plugin-proposal-numeric-separator", | ||
"@babel/plugin-proposal-throw-expressions", | ||
"@babel/plugin-proposal-export-default-from", | ||
"@babel/plugin-proposal-logical-assignment-operators", | ||
"@babel/plugin-proposal-optional-chaining", | ||
[ | ||
"@babel/plugin-proposal-pipeline-operator", | ||
{ | ||
"proposal": "minimal" | ||
} | ||
], | ||
"@babel/plugin-proposal-nullish-coalescing-operator", | ||
"@babel/plugin-proposal-do-expressions", | ||
"@babel/plugin-proposal-function-bind" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# CHANGELOG | ||
|
||
### 1.0.1 | ||
- Update dependencies | ||
|
||
### 1.0.0 | ||
- Support redux-saga 1.0.1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,139 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.sagaMiddleware = exports.SagaManager = exports.CANCEL_SAGAS_HMR = exports.reloadReducer = exports.injectReducer = undefined; | ||
|
||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
|
||
var _keys2 = _interopRequireDefault(_keys); | ||
|
||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
|
||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
|
||
var _regenerator = require('babel-runtime/regenerator'); | ||
|
||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
|
||
var _reduxReducersInjector = require('redux-reducers-injector'); | ||
|
||
Object.defineProperty(exports, 'injectReducer', { | ||
enumerable: true, | ||
get: function get() { | ||
return _reduxReducersInjector.injectReducer; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'reloadReducer', { | ||
enumerable: true, | ||
get: function get() { | ||
return _reduxReducersInjector.reloadReducer; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.reloadSaga = reloadSaga; | ||
exports.injectSaga = injectSaga; | ||
exports.createInjectSagasStore = createInjectSagasStore; | ||
Object.defineProperty(exports, "injectReducer", { | ||
enumerable: true, | ||
get: function get() { | ||
return _reduxReducersInjector.injectReducer; | ||
} | ||
}); | ||
Object.defineProperty(exports, "reloadReducer", { | ||
enumerable: true, | ||
get: function get() { | ||
return _reduxReducersInjector.reloadReducer; | ||
} | ||
}); | ||
exports["default"] = exports.sagaMiddleware = exports.SagaManager = exports.CANCEL_SAGAS_HMR = void 0; | ||
|
||
var _reduxSaga = require('redux-saga'); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
|
||
var _reduxSaga2 = _interopRequireDefault(_reduxSaga); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
|
||
var _effects = require('redux-saga/effects'); | ||
var _reduxReducersInjector = require("redux-reducers-injector"); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _reduxSaga = _interopRequireDefault(require("redux-saga")); | ||
|
||
var CANCEL_SAGAS_HMR = exports.CANCEL_SAGAS_HMR = 'CANCEL_SAGAS_HMR'; | ||
var _effects = require("redux-saga/effects"); | ||
|
||
/** | ||
* Created by guillaume on 1/17/17. | ||
*/ | ||
var CANCEL_SAGAS_HMR = 'CANCEL_SAGAS_HMR'; | ||
exports.CANCEL_SAGAS_HMR = CANCEL_SAGAS_HMR; | ||
var original_store = {}; | ||
|
||
function createAbortableSaga(key, saga) { | ||
if (process.env.NODE_ENV === 'development') { | ||
return (/*#__PURE__*/_regenerator2.default.mark(function main() { | ||
var sagaTask, _ref, payload; | ||
|
||
return _regenerator2.default.wrap(function main$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _effects.fork)(saga); | ||
|
||
case 2: | ||
sagaTask = _context.sent; | ||
_context.next = 5; | ||
return (0, _effects.take)(CANCEL_SAGAS_HMR); | ||
|
||
case 5: | ||
_ref = _context.sent; | ||
payload = _ref.payload; | ||
|
||
if (!(payload === key)) { | ||
_context.next = 10; | ||
break; | ||
} | ||
|
||
_context.next = 10; | ||
return (0, _effects.cancel)(sagaTask); | ||
|
||
case 10: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, main, this); | ||
}) | ||
); | ||
} else { | ||
return saga; | ||
} | ||
if (process.env.NODE_ENV === 'development') { | ||
return ( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function main() { | ||
var sagaTask, _ref, payload; | ||
|
||
return _regenerator["default"].wrap(function main$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _effects.fork)(saga); | ||
|
||
case 2: | ||
sagaTask = _context.sent; | ||
_context.next = 5; | ||
return (0, _effects.take)(CANCEL_SAGAS_HMR); | ||
|
||
case 5: | ||
_ref = _context.sent; | ||
payload = _ref.payload; | ||
|
||
if (!(payload === key)) { | ||
_context.next = 10; | ||
break; | ||
} | ||
|
||
_context.next = 10; | ||
return (0, _effects.cancel)(sagaTask); | ||
|
||
case 10: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, main); | ||
}) | ||
); | ||
} else { | ||
return saga; | ||
} | ||
} | ||
|
||
var SagaManager = exports.SagaManager = { | ||
startSaga: function startSaga(key, saga) { | ||
sagaMiddleware.run(createAbortableSaga(key, saga)); | ||
}, | ||
cancelSaga: function cancelSaga(key) { | ||
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : original_store; | ||
|
||
store.dispatch({ | ||
type: CANCEL_SAGAS_HMR, | ||
payload: key | ||
}); | ||
} | ||
var SagaManager = { | ||
startSaga: function startSaga(key, saga) { | ||
sagaMiddleware.run(createAbortableSaga(key, saga)); | ||
}, | ||
cancelSaga: function cancelSaga(key) { | ||
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : original_store; | ||
store.dispatch({ | ||
type: CANCEL_SAGAS_HMR, | ||
payload: key | ||
}); | ||
} | ||
}; | ||
exports.SagaManager = SagaManager; | ||
|
||
function reloadSaga(key, saga) { | ||
var store = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : original_store; | ||
|
||
SagaManager.cancelSaga(key, store); | ||
SagaManager.startSaga(key, saga); | ||
var store = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : original_store; | ||
SagaManager.cancelSaga(key, store); | ||
SagaManager.startSaga(key, saga); | ||
} | ||
|
||
function injectSaga(key, saga) { | ||
var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var store = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : original_store; | ||
|
||
// If already set, do nothing, except force is specified | ||
var exists = store.injectedSagas.includes(key); | ||
if (!exists || force) { | ||
if (!exists) { | ||
store.injectedSagas = [].concat((0, _toConsumableArray3.default)(store.injectedSagas), [key]); | ||
} | ||
if (force) { | ||
SagaManager.cancelSaga(key, store); | ||
} | ||
SagaManager.startSaga(key, saga, store); | ||
var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var store = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : original_store; | ||
// If already set, do nothing, except force is specified | ||
var exists = store.injectedSagas.includes(key); | ||
|
||
if (!exists || force) { | ||
if (!exists) { | ||
store.injectedSagas = [].concat((0, _toConsumableArray2["default"])(store.injectedSagas), [key]); | ||
} | ||
} | ||
|
||
function createInjectSagasStore(rootSaga, initialReducers) { | ||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
if (force) { | ||
SagaManager.cancelSaga(key, store); | ||
} | ||
|
||
original_store = _reduxReducersInjector.createInjectStore.apply(undefined, [initialReducers].concat(args)); | ||
original_store.injectedSagas = []; | ||
|
||
injectSaga((0, _keys2.default)(rootSaga)[0], rootSaga[(0, _keys2.default)(rootSaga)[0]], false, original_store); | ||
|
||
return original_store; | ||
SagaManager.startSaga(key, saga, store); | ||
} | ||
} | ||
|
||
var sagaMiddleware = exports.sagaMiddleware = (0, _reduxSaga2.default)(); | ||
function createInjectSagasStore(rootSaga, initialReducers) { | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
|
||
original_store = _reduxReducersInjector.createInjectStore.apply(void 0, [initialReducers].concat(args)); | ||
original_store.injectedSagas = []; | ||
injectSaga(Object.keys(rootSaga)[0], rootSaga[Object.keys(rootSaga)[0]], false, original_store); | ||
return original_store; | ||
} | ||
|
||
exports.default = createInjectSagasStore; | ||
var sagaMiddleware = (0, _reduxSaga["default"])(); | ||
exports.sagaMiddleware = sagaMiddleware; | ||
var _default = createInjectSagasStore; | ||
exports["default"] = _default; |
Oops, something went wrong.