Comparing version 0.5.0 to 1.0.0
{ | ||
"name": "ts-bus", | ||
"version": "0.5.0", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -18,2 +18,3 @@ "use strict"; | ||
var react_1 = __importDefault(require("react")); | ||
var react_test_renderer_1 = require("react-test-renderer"); | ||
var react_hooks_1 = require("@testing-library/react-hooks"); | ||
@@ -113,2 +114,41 @@ var react_2 = require("./react"); | ||
}); | ||
it("should not loose events during the render cycle when mounted.", function (done) { | ||
var myBus = new EventBus_1.EventBus(); | ||
var reducer = jest.fn(function (s) { return s; }); | ||
var EVENT_DELAY = { type: "myevent", payload: "DELAY" }; | ||
var EVENT_URGENT = { type: "myevent", payload: "URGENT" }; | ||
function MyContextProvider(props) { | ||
react_2.useBusReducer({}, reducer); | ||
return props.children; | ||
} | ||
function EventPublisher() { | ||
var b = react_2.useBus(); | ||
react_1.default.useEffect(function () { | ||
setTimeout(function () { | ||
b.publish(EVENT_DELAY); | ||
}, 0); | ||
}, [b]); | ||
react_1.default.useEffect(function () { | ||
b.publish(EVENT_URGENT); | ||
}, [b]); | ||
return react_1.default.createElement("div", null); | ||
} | ||
function App() { | ||
return (react_1.default.createElement(react_2.BusProvider, { value: myBus }, | ||
react_1.default.createElement(MyContextProvider, null, | ||
react_1.default.createElement(EventPublisher, null)))); | ||
} | ||
// render the component | ||
react_hooks_1.act(function () { | ||
react_test_renderer_1.create(react_1.default.createElement(App, null)); | ||
}); | ||
setTimeout(function () { | ||
var eventList = reducer.mock.calls.map(function (_a) { | ||
var ev = _a[1]; | ||
return ev; | ||
}); | ||
expect(eventList).toEqual([EVENT_URGENT, EVENT_DELAY]); | ||
done(); | ||
}, 0); | ||
}); | ||
//# sourceMappingURL=react.test.js.map |
@@ -15,4 +15,4 @@ "use strict"; | ||
var _a = react_1.useReducer(reducer, initState), state = _a[0], dispatch = _a[1]; | ||
// Run the subscriber | ||
react_1.useEffect(function () { return subscriber(dispatch, bus); }, [subscriber, dispatch, bus]); | ||
// Run the subscriber synchronously | ||
react_1.useLayoutEffect(function () { return subscriber(dispatch, bus); }, [subscriber, dispatch, bus]); | ||
return state; | ||
@@ -19,0 +19,0 @@ } |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
276326
586
1