rel-events
Advanced tools
Comparing version 0.3.3 to 0.4.0
@@ -115,3 +115,5 @@ // eslint-disable-next-line import/named | ||
type: 'TEST_EVENT', | ||
test: 'yes', | ||
extraData: { | ||
test: 'yes', | ||
}, | ||
shouldDispatch: expect.any(Function), | ||
@@ -128,3 +130,5 @@ }; | ||
type: 'TEST_EVENT', | ||
test: 'yes', | ||
extraData: { | ||
test: 'yes', | ||
}, | ||
shouldDispatch, | ||
@@ -131,0 +135,0 @@ }; |
@@ -16,4 +16,2 @@ "use strict"; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
@@ -23,6 +21,2 @@ | ||
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) { (0, _defineProperty2.default)(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; } | ||
var Event = function Event() { | ||
@@ -40,9 +34,10 @@ var _this = this; | ||
this.toRedux = function (data) { | ||
return _objectSpread({ | ||
this.toRedux = function (dispatchData) { | ||
return { | ||
type: _this.reducerName, | ||
shouldDispatch: _this.manager.shouldDispatch || function () { | ||
return true; | ||
} | ||
}, data); | ||
}, | ||
extraData: dispatchData | ||
}; | ||
}; | ||
@@ -49,0 +44,0 @@ |
## Advanced Usage: Other features and goodies | ||
### Using `extraData` on Event Managers | ||
Whenever you call an Event/HTTPEvent, data that is passed to its 'call' or 'onDispatch' method is automatically added to the event instance in the `extraData` key. | ||
That means that if, for example, you want to persist some data on an Event, you may just do this: | ||
```js | ||
// on eventManagers.js | ||
export class ExampleEventManager { | ||
name: 'login', | ||
manager: { | ||
initialState: {}, | ||
// just set a new key passing the event.extraData value | ||
onDispatch: (state, event) => ({ ...state, data: event.extraData }) | ||
}, | ||
} | ||
``` | ||
### Event Chaining - Making Events listen to Events | ||
@@ -5,0 +25,0 @@ |
@@ -38,6 +38,6 @@ import { connect } from 'react-redux'; | ||
toRedux = data => ({ | ||
toRedux = dispatchData => ({ | ||
type: this.reducerName, | ||
shouldDispatch: this.manager.shouldDispatch || (() => true), | ||
...data, | ||
extraData: dispatchData, | ||
}); | ||
@@ -44,0 +44,0 @@ |
{ | ||
"name": "rel-events", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"description": "The relevant React Events Library. Events framework based on redux to decouple our from business logic and make state management easy.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164868