reactotron-core-client
Version:
Grants Reactotron clients the ability to talk to a Reactotron server.
46 lines (45 loc) • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hasStateResponsePlugin = exports.default = exports.assertHasStateResponsePlugin = void 0;
/**
* Provides helper functions for send state responses.
*/
const stateResponse = () => reactotron => {
return {
features: {
stateActionComplete: (name, action, important = false) => reactotron.send("state.action.complete", {
name,
action
}, !!important),
stateValuesResponse: (path, value, valid = true) => reactotron.send("state.values.response", {
path,
value,
valid
}),
stateKeysResponse: (path, keys, valid = true) => reactotron.send("state.keys.response", {
path,
keys,
valid
}),
stateValuesChange: changes => changes.length > 0 && reactotron.send("state.values.change", {
changes
}),
/** sends the state backup over to the server */
stateBackupResponse: state => reactotron.send("state.backup.response", {
state
})
}
};
};
var _default = exports.default = stateResponse;
const hasStateResponsePlugin = reactotron => reactotron && "stateActionComplete" in reactotron && typeof reactotron.stateActionComplete === "function" && "stateValuesResponse" in reactotron && typeof reactotron.stateValuesResponse === "function" && "stateKeysResponse" in reactotron && typeof reactotron.stateKeysResponse === "function" && "stateValuesChange" in reactotron && typeof reactotron.stateValuesChange === "function" && "stateBackupResponse" in reactotron && typeof reactotron.stateBackupResponse === "function";
exports.hasStateResponsePlugin = hasStateResponsePlugin;
const assertHasStateResponsePlugin = reactotron => {
if (!hasStateResponsePlugin(reactotron)) {
throw new Error("This Reactotron client has not had the state responses plugin applied to it. Make sure that you add `use(stateResponse())` before adding this plugin.");
}
};
exports.assertHasStateResponsePlugin = assertHasStateResponsePlugin;
//# sourceMappingURL=state-responses.js.map