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

reductive-dev-tools

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reductive-dev-tools - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

55

lib/js/src/connectors.bs.js

@@ -581,18 +581,43 @@ // Generated by BUCKLESCRIPT VERSION 4.0.18, PLEASE EDIT WITH CARE

function send(connectionId, action, state) {
var connectionInfo = unwrap(Js_dict.get(connections, connectionId), [
ConnectionNotFound,
"DevTool connection(id=$connectionId) not found"
]);
connectionInfo[/* retainedState */0] = state;
var exit = 0;
if (typeof action === "number" || action[0] !== 161605709) {
exit = 1;
function componentReducerEnhancer(connectionId, reducer, action, state) {
var match = Js_dict.get(connections, connectionId);
if (match !== undefined) {
var connectionInfo = match;
var propageAction = function (state, action) {
var result = Curry._2(reducer, action, state);
var exit = 0;
if (typeof action === "number") {
exit = 1;
} else if (action[0] !== 161605709) {
exit = 1;
}
if (exit === 1) {
if (typeof result !== "number") {
if (!result.tag) {
var state$1 = result[0];
connectionInfo[/* meta */2][/* actionCount */2] = connectionInfo[/* meta */2][/* actionCount */2] + 1 | 0;
connectionInfo[/* retainedState */0] = state$1;
Extension$ReductiveDevTools.send(connectionInfo[/* connection */1], Curry._2(serializeMaybeVariant, action, false), Curry._1(serializeObject, state$1));
}
}
}
return result;
};
var match$1 = connectionInfo[/* meta */2][/* rewindActionIdx */1];
if (match$1 !== undefined) {
var isDevToolsStateUpdateAction = typeof action === "number" ? false : action[0] === 161605709;
if (match$1 >= connectionInfo[/* meta */2][/* actionCount */2] || isDevToolsStateUpdateAction) {
return propageAction(state, action);
} else {
return /* NoUpdate */0;
}
} else {
return propageAction(state, action);
}
} else {
return /* () */0;
console.warn("reductive-dev-tools connection not found while expected");
return Curry._2(reducer, action, state);
}
if (exit === 1) {
return Extension$ReductiveDevTools.send(connectionInfo[/* connection */1], Curry._2(serializeMaybeVariant, action, false), Curry._1(serializeObject, state));
}
}

@@ -603,3 +628,3 @@

exports.unsubscribe = unsubscribe;
exports.send = send;
exports.componentReducerEnhancer = componentReducerEnhancer;
/* serializeMaybeVariant Not a pure module */
{
"name": "reductive-dev-tools",
"version": "0.1.5",
"version": "0.1.6",
"description": "reductive and reason-react reducer component integration with Redux DevTools",

@@ -5,0 +5,0 @@ "main": "lib/js/src/reductiveDevTools.bs.js",

@@ -52,3 +52,3 @@ ## reductive-dev-tools

## Experimental: ReasonReact reducer component via direct API
## Usage with ReactReason reducer component

@@ -71,52 +71,19 @@ 1. Create devtools connection with `ReductiveDevTools.Connectors.register()`.

```
2. Retain an action... inside your component state... (yeah...)
2. Wrap your reducer into `componentReducerEnhancer` with passed connectionId and handle actions dispatched from the monitor (`DevToolStateUpdate('state)`) to support rewind, revert, import extension features:
```reason
/* State declaration */
type state = {
count: int,
show: bool,
preserved: preservedAction
} and preservedAction = {
action: option([`Click(unit) | `Toggle(unit) | `DevToolStateUpdate(state)])
};
/* your reducer */
reducer: (action, state) => {
let stateWithAction = {...state, preserved: { action: Some(action) }};
switch (action) {
| `Click(_) => ReasonReact.Update({...stateWithAction, count: state.count + 1})
| `Toggle(_) => ReasonReact.Update({...stateWithAction, show: !state.show})
| `DevToolStateUpdate(devToolsState) => ReasonReact.Update({...devToolsState, preserved: { action: Some(action) }})
}
/* inside your component */
reducer: ReductiveDevTools.Connectors.componentReducerEnhancer(connectionId, ((action, state) => {
switch (action) {
| `Click(_) => ReasonReact.Update({...state, count: state.count + 1})
| `Toggle(_) => ReasonReact.Update({...state, show: !state.show})
/* handle the actions dispatched from the dev tools monitor */
| `DevToolStateUpdate(devToolsState) => ReasonReact.Update(devToolsState)
}
})),
},
```
3. Send new state and action with `ReductiveDevTools.Connectors.send()`
3. Unsubscribe when needed with `ReductiveDevTools.Connectors.unsubscribe(~connectionId)`
```reason
/* in your component */
willUpdate: ({newSelf}) =>
switch(newSelf.state.preserved.action){
| Some(action) => ReductiveDevTools.Connectors.send(~connectionId, ~action, ~state=newSelf.state);
| None => ()
},
```
4. Handle actions dispatched from the monitor (`DevToolStateUpdate('state)`)
```reason
/* your reducer */
reducer: (action, state) => {
let stateWithAction = {...state, preserved: { action: Some(action) }};
switch (action) {
/* other actions */
| `DevToolStateUpdate(devToolsState) => ReasonReact.Update({...devToolsState, preserved: { action: Some(action) }})
}
},
```
5. Unsubscribe when needed with `ReductiveDevTools.Connectors.unsubscribe(~connectionId)`
## Options

@@ -123,0 +90,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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