reductive-dev-tools
Advanced tools
Comparing version 0.1.8 to 0.2.0
@@ -16,119 +16,4 @@ // Generated by BUCKLESCRIPT VERSION 4.0.18, PLEASE EDIT WITH CARE | ||
var Extension$ReductiveDevTools = require("./extension.bs.js"); | ||
var Utilities$ReductiveDevTools = require("./utilities.bs.js"); | ||
function unwrap(opt, exc) { | ||
if (opt !== undefined) { | ||
return Caml_option.valFromOption(opt); | ||
} else { | ||
throw exc; | ||
} | ||
} | ||
var serializeMaybeVariant = ( | ||
function _serialize(obj, isNonRoot) { | ||
if(!obj){ return obj } | ||
/* handle plain variants */ | ||
if(typeof obj === 'number' && !isNonRoot){ | ||
return { | ||
type: 'update', | ||
_rawValue: obj | ||
} | ||
} | ||
const symbols = Object.getOwnPropertySymbols(obj); | ||
const variantNameSymbolIdx = symbols.findIndex(symbol => String(symbol) == 'Symbol(BsVariant)' || String(symbol) == 'Symbol(BsPolyVar)'); | ||
const recordSymbolIdx = symbols.findIndex(symbol => String(symbol) == 'Symbol(BsRecord)'); | ||
if(variantNameSymbolIdx > -1){ | ||
const variantName = obj[symbols[variantNameSymbolIdx]]; | ||
return { | ||
...Object.keys(obj).reduce((target, key) => ({ | ||
...target, | ||
[key != 'tag' ? 'arg_'+key : key]: _serialize(obj[key], true) | ||
}),{}), | ||
type: variantName | ||
} | ||
} else if(recordSymbolIdx > -1) { | ||
const keys = obj[symbols[recordSymbolIdx]]; | ||
return keys.reduce((object, key, index) => ({ | ||
...object, | ||
[key]: _serialize(obj[index], true) | ||
}), {}) | ||
/** | ||
* handle root discriminated unions when -bs-g flag is not set | ||
* smilarly to plain variants | ||
*/ | ||
} else if(Array.isArray(obj) && !isNonRoot){ | ||
return { | ||
type: 'update', | ||
_rawValue: obj, | ||
// pass tag since extension will ignore other keys inside arrays | ||
_variant_tag: obj.tag | ||
} | ||
} else { | ||
return obj | ||
} | ||
} | ||
); | ||
var serializeObject = ( | ||
function _serialize(obj) { | ||
if(!obj){ return obj } | ||
const symbols = Object.getOwnPropertySymbols(obj); | ||
const variantNameSymbolIdx = symbols.findIndex(symbol => String(symbol) == 'Symbol(BsVariant)' || String(symbol) == 'Symbol(BsPolyVar)'); | ||
const recordSymbolIdx = symbols.findIndex(symbol => String(symbol) == 'Symbol(BsRecord)'); | ||
if(variantNameSymbolIdx > -1){ | ||
const variantName = obj[symbols[variantNameSymbolIdx]]; | ||
return { | ||
...Object.keys(obj).reduce((target, key) => ({ | ||
...target, | ||
[key != 'tag' ? 'arg_'+key : key]: _serialize(obj[key]) | ||
}),{}), | ||
type: variantName | ||
} | ||
} else if(recordSymbolIdx > -1) { | ||
const keys = obj[symbols[recordSymbolIdx]]; | ||
return keys.reduce((object, key, index) => ({ | ||
...object, | ||
[key]: _serialize(obj[index]) | ||
}), {}) | ||
} else { | ||
return obj | ||
} | ||
} | ||
); | ||
var deserializeObject = ( | ||
function _serialize(obj) { | ||
if(!obj){ return obj } | ||
return Object.keys(obj).reduce((target, key) => [ | ||
...target, | ||
(typeof obj[key] === 'object') ? _serialize(obj[key]) : obj[key] | ||
], []) | ||
} | ||
); | ||
var deserializeVariant = ( | ||
function _serialize(obj) { | ||
if(!obj){ return obj } | ||
// restore plain variants and variants when running without -bs-g flag back | ||
if(obj.type == 'update' && obj._rawValue !== undefined){ | ||
let target = obj._rawValue | ||
if(obj._variant_tag !== undefined){ | ||
target.tag = obj._variant_tag | ||
} | ||
return target | ||
} | ||
let target = Object.keys(obj).filter(key => key != 'tag' && key != 'type').reduce((target, key) => [ | ||
...target, | ||
(typeof obj[key] === 'object') ? _serialize(obj[key]) : obj[key] | ||
], []); | ||
target.tag = obj.tag; | ||
return target | ||
} | ||
); | ||
var evalMethod = ( | ||
@@ -199,3 +84,3 @@ function evalMethod(action, obj) { | ||
var initialState = Caml_array.caml_array_get(computedStates, initialIdx).state; | ||
mutateState(Curry._1(deserializeObject, initialState), store); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](initialState), store); | ||
var preservedActionCount = meta[/* actionCount */2]; | ||
@@ -205,8 +90,8 @@ $$Array.iter((function (i) { | ||
var targetAction = Belt_Option.getExn(Js_dict.get(actionsById, stagedActionKey)).action; | ||
Curry._1(store[/* component */0][/* send */3], Curry._1(deserializeVariant, targetAction)); | ||
var connectionInfo = unwrap(Js_dict.get(connections, meta[/* connectionId */3]), [ | ||
Curry._1(store[/* component */0][/* send */3], Utilities$ReductiveDevTools.Serializer[/* deserializeAction */3](targetAction)); | ||
var connectionInfo = Utilities$ReductiveDevTools.unwrap(Js_dict.get(connections, meta[/* connectionId */3]), [ | ||
ConnectionNotFound, | ||
"DevTool connection(id=$connectionId) not found" | ||
]); | ||
var match = Curry._2(connectionInfo[/* retainedReducer */1], Curry._1(deserializeVariant, targetAction), connectionInfo[/* retainedState */0]); | ||
var match = Curry._2(connectionInfo[/* retainedReducer */1], Utilities$ReductiveDevTools.Serializer[/* deserializeAction */3](targetAction), connectionInfo[/* retainedState */0]); | ||
var tmp; | ||
@@ -216,3 +101,3 @@ tmp = typeof match === "number" || match.tag ? connectionInfo[/* retainedState */0] : match[0]; | ||
var newState = connectionInfo[/* retainedState */0]; | ||
Caml_array.caml_array_get(computedStates, i).state = Curry._1(serializeObject, newState); | ||
Caml_array.caml_array_get(computedStates, i).state = Utilities$ReductiveDevTools.Serializer[/* serializeObject */2](newState); | ||
return /* () */0; | ||
@@ -229,3 +114,3 @@ }), Belt_Array.keep(Belt_Array.range(skipped ? start : start + 1 | 0, stagedActions.length - 1 | 0), (function (i) { | ||
var targetState = Caml_array.caml_array_get(computedStates, liftedState.currentStateIndex).state; | ||
mutateState(Curry._1(deserializeObject, targetState), store); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](targetState), store); | ||
} | ||
@@ -263,3 +148,3 @@ if (skipped) { | ||
var initialState = Caml_array.caml_array_get(computedStates, initialIdx).state; | ||
var state = Curry._1(deserializeObject, initialState); | ||
var state = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](initialState); | ||
store[/* state */0] = state; | ||
@@ -270,6 +155,6 @@ var preservedActionCount = meta[/* actionCount */2]; | ||
var targetAction = Belt_Option.getExn(Js_dict.get(actionsById, stagedActionKey)).action; | ||
var action = Curry._1(deserializeVariant, targetAction); | ||
var action = Utilities$ReductiveDevTools.Serializer[/* deserializeAction */3](targetAction); | ||
Reductive.Store[/* dispatch */4](store, action); | ||
var newState = Reductive.Store[/* getState */5](store); | ||
Caml_array.caml_array_get(computedStates, i).state = Curry._1(serializeObject, newState); | ||
Caml_array.caml_array_get(computedStates, i).state = Utilities$ReductiveDevTools.Serializer[/* serializeObject */2](newState); | ||
return /* () */0; | ||
@@ -286,3 +171,3 @@ }), Belt_Array.keep(Belt_Array.range(skipped ? start : start + 1 | 0, stagedActions.length - 1 | 0), (function (i) { | ||
var targetState = Caml_array.caml_array_get(computedStates, liftedState.currentStateIndex).state; | ||
var state$1 = Curry._1(deserializeObject, targetState); | ||
var state$1 = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](targetState); | ||
store[/* state */0] = state$1; | ||
@@ -301,5 +186,5 @@ notifyListeners(store); | ||
function handle(connection, store, meta, actionCreators) { | ||
function handle(connection, store, meta, actionCreators, param) { | ||
var initialState = Reductive.Store[/* getState */5](store); | ||
Extension$ReductiveDevTools.init(connection, Curry._1(serializeObject, initialState)); | ||
Extension$ReductiveDevTools.init(connection, Utilities$ReductiveDevTools.Serializer[/* serializeObject */2](initialState)); | ||
Extension$ReductiveDevTools.subscribe(connection, (function (action) { | ||
@@ -312,3 +197,3 @@ var match = action.type; | ||
var actionCreators$1 = actionCreators; | ||
var payload = unwrap(Caml_option.undefined_to_opt(action$1.payload), [ | ||
var payload = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$1.payload), [ | ||
PayloadNotFound$1, | ||
@@ -329,3 +214,3 @@ "action doesn't contain payload while expected" | ||
var meta$1 = meta; | ||
var payload$1 = unwrap(Caml_option.undefined_to_opt(action$3.payload), [ | ||
var payload$1 = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$3.payload), [ | ||
PayloadNotFound$1, | ||
@@ -350,3 +235,3 @@ "action doesn't contain payload while expected" | ||
var targetState = Caml_array.caml_array_get(computedStates, computedStates.length - 1 | 0).state; | ||
var state = Curry._1(deserializeObject, targetState); | ||
var state = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](targetState); | ||
store$3[/* state */0] = state; | ||
@@ -366,7 +251,7 @@ notifyListeners(store$3); | ||
case "ROLLBACK" : | ||
var stateString = unwrap(Caml_option.undefined_to_opt(action$4.state), [ | ||
var stateString = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$4.state), [ | ||
StateNotFound$1, | ||
"action(" + (String(payloadType) + ") doesn\'t contain state while expected") | ||
]); | ||
var state$1 = Curry._1(deserializeObject, JSON.parse(stateString)); | ||
var state$1 = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](Utilities$ReductiveDevTools.parse(stateString)); | ||
store$3[/* state */0] = state$1; | ||
@@ -380,3 +265,3 @@ notifyListeners(store$3); | ||
case "TOGGLE_ACTION" : | ||
var stateString$1 = unwrap(Caml_option.undefined_to_opt(action$4.state), [ | ||
var stateString$1 = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$4.state), [ | ||
StateNotFound$1, | ||
@@ -386,3 +271,3 @@ "action(" + (String(payloadType) + ") doesn\'t contain state while expected") | ||
if (Belt_Option.isSome(meta$2[/* rewindActionIdx */1]) && Belt_Option.getExn(meta$2[/* rewindActionIdx */1]) >= meta$2[/* actionCount */2] || Belt_Option.isNone(meta$2[/* rewindActionIdx */1])) { | ||
var liftedState = JSON.parse(stateString$1); | ||
var liftedState = Utilities$ReductiveDevTools.parse(stateString$1); | ||
Extension$ReductiveDevTools.send(devTools$1, null, processToogleAction$1(store$3, payload$2, liftedState, meta$2)); | ||
@@ -397,3 +282,3 @@ return notifyListeners(store$3); | ||
if (exit === 1) { | ||
var stateString$2 = unwrap(Caml_option.undefined_to_opt(action$4.state), [ | ||
var stateString$2 = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$4.state), [ | ||
StateNotFound$1, | ||
@@ -417,10 +302,10 @@ "action(" + (String(payloadType) + ") doesn\'t contain state while expected") | ||
var targetState$1 = Caml_array.caml_array_get(computedStates$1, nonSkippedIdx).state; | ||
var state$2 = Curry._1(deserializeObject, targetState$1); | ||
var state$2 = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](targetState$1); | ||
store$3[/* state */0] = state$2; | ||
} else { | ||
var state$3 = Curry._1(deserializeObject, JSON.parse(stateString$2)); | ||
var state$3 = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](Utilities$ReductiveDevTools.parse(stateString$2)); | ||
store$3[/* state */0] = state$3; | ||
} | ||
} else { | ||
var state$4 = Curry._1(deserializeObject, JSON.parse(stateString$2)); | ||
var state$4 = Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](Utilities$ReductiveDevTools.parse(stateString$2)); | ||
store$3[/* state */0] = state$4; | ||
@@ -499,3 +384,3 @@ } | ||
meta[/* actionCount */2] = meta[/* actionCount */2] + 1 | 0; | ||
return Extension$ReductiveDevTools.send(devTools, Curry._2(serializeMaybeVariant, action$1, false), Curry._1(serializeObject, Reductive.Store[/* getState */5](store$1))); | ||
return Extension$ReductiveDevTools.send(devTools, Utilities$ReductiveDevTools.Serializer[/* serializeAction */1](action$1), Utilities$ReductiveDevTools.Serializer[/* serializeObject */2](Reductive.Store[/* getState */5](store$1))); | ||
} | ||
@@ -505,3 +390,3 @@ }; | ||
var actionCreators = targetOptions.actionCreators; | ||
handle(devTools, store, meta, actionCreators === undefined ? undefined : Caml_option.some(actionCreators)); | ||
handle(devTools, store, meta, actionCreators === undefined ? undefined : Caml_option.some(actionCreators), /* () */0); | ||
return store; | ||
@@ -521,3 +406,3 @@ } | ||
component[/* state */1], | ||
(function (action, state) { | ||
(function (_action, _state) { | ||
return /* NoUpdate */0; | ||
@@ -550,3 +435,3 @@ }), | ||
var initialState = getState(store); | ||
Extension$ReductiveDevTools.init(connection, Curry._1(serializeObject, initialState)); | ||
Extension$ReductiveDevTools.init(connection, Utilities$ReductiveDevTools.Serializer[/* serializeObject */2](initialState)); | ||
Extension$ReductiveDevTools.subscribe(connection, (function (action) { | ||
@@ -559,3 +444,3 @@ var match = action.type; | ||
var actionCreators$2 = actionCreators$1; | ||
var payload = unwrap(Caml_option.undefined_to_opt(action$1.payload), [ | ||
var payload = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$1.payload), [ | ||
PayloadNotFound, | ||
@@ -575,3 +460,3 @@ "action doesn't contain payload while expected" | ||
var meta$1 = meta; | ||
var payload$1 = unwrap(Caml_option.undefined_to_opt(action$2.payload), [ | ||
var payload$1 = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$2.payload), [ | ||
PayloadNotFound, | ||
@@ -596,3 +481,3 @@ "action doesn't contain payload while expected" | ||
var targetState = Caml_array.caml_array_get(computedStates, computedStates.length - 1 | 0).state; | ||
mutateState(Curry._1(deserializeObject, targetState), store$3); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](targetState), store$3); | ||
meta$2[/* actionCount */2] = nextLiftedState.nextActionId - 1 | 0; | ||
@@ -609,7 +494,7 @@ return Extension$ReductiveDevTools.send(devTools$1, null, nextLiftedState); | ||
case "ROLLBACK" : | ||
var stateString = unwrap(Caml_option.undefined_to_opt(action$3.state), [ | ||
var stateString = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$3.state), [ | ||
StateNotFound, | ||
"action(" + (String(payloadType) + ") doesn\'t contain state while expected") | ||
]); | ||
mutateState(Curry._1(deserializeObject, JSON.parse(stateString)), store$3); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](Utilities$ReductiveDevTools.parse(stateString)), store$3); | ||
meta$2[/* actionCount */2] = 0; | ||
@@ -621,3 +506,3 @@ return Extension$ReductiveDevTools.init(devTools$1, getState(store$3)); | ||
case "TOGGLE_ACTION" : | ||
var stateString$1 = unwrap(Caml_option.undefined_to_opt(action$3.state), [ | ||
var stateString$1 = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$3.state), [ | ||
StateNotFound, | ||
@@ -627,3 +512,3 @@ "action(" + (String(payloadType) + ") doesn\'t contain state while expected") | ||
if (Belt_Option.isSome(meta$2[/* rewindActionIdx */1]) && Belt_Option.getExn(meta$2[/* rewindActionIdx */1]) >= meta$2[/* actionCount */2] || Belt_Option.isNone(meta$2[/* rewindActionIdx */1])) { | ||
var liftedState = JSON.parse(stateString$1); | ||
var liftedState = Utilities$ReductiveDevTools.parse(stateString$1); | ||
Extension$ReductiveDevTools.send(devTools$1, null, processToogleAction(store$3, payload$2, liftedState, meta$2)); | ||
@@ -638,3 +523,3 @@ return /* () */0; | ||
if (exit === 1) { | ||
var stateString$2 = unwrap(Caml_option.undefined_to_opt(action$3.state), [ | ||
var stateString$2 = Utilities$ReductiveDevTools.unwrap(Caml_option.undefined_to_opt(action$3.state), [ | ||
StateNotFound, | ||
@@ -658,8 +543,8 @@ "action(" + (String(payloadType) + ") doesn\'t contain state while expected") | ||
var targetState$1 = Caml_array.caml_array_get(computedStates$1, nonSkippedIdx).state; | ||
mutateState(Curry._1(deserializeObject, targetState$1), store$3); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](targetState$1), store$3); | ||
} else { | ||
mutateState(Curry._1(deserializeObject, JSON.parse(stateString$2)), store$3); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](Utilities$ReductiveDevTools.parse(stateString$2)), store$3); | ||
} | ||
} else { | ||
mutateState(Curry._1(deserializeObject, JSON.parse(stateString$2)), store$3); | ||
mutateState(Utilities$ReductiveDevTools.Serializer[/* deserializeObject */4](Utilities$ReductiveDevTools.parse(stateString$2)), store$3); | ||
} | ||
@@ -678,3 +563,3 @@ return /* () */0; | ||
function unsubscribe(connectionId) { | ||
var connectionInfo = unwrap(Js_dict.get(connections, connectionId), [ | ||
var connectionInfo = Utilities$ReductiveDevTools.unwrap(Js_dict.get(connections, connectionId), [ | ||
ConnectionNotFound, | ||
@@ -701,11 +586,20 @@ "DevTool connection(id=$connectionId) not found" | ||
if (exit === 1) { | ||
var exit$1 = 0; | ||
if (typeof result !== "number") { | ||
if (!result.tag) { | ||
var state$1 = result[0]; | ||
connectionInfo[/* meta */3][/* actionCount */2] = connectionInfo[/* meta */3][/* actionCount */2] + 1 | 0; | ||
connectionInfo[/* retainedState */0] = state$1; | ||
Extension$ReductiveDevTools.send(connectionInfo[/* connection */2], Curry._2(serializeMaybeVariant, action, false), Curry._1(serializeObject, state$1)); | ||
switch (result.tag | 0) { | ||
case 1 : | ||
break; | ||
case 0 : | ||
case 2 : | ||
exit$1 = 2; | ||
break; | ||
} | ||
} | ||
if (exit$1 === 2) { | ||
var state$1 = result[0]; | ||
connectionInfo[/* meta */3][/* actionCount */2] = connectionInfo[/* meta */3][/* actionCount */2] + 1 | 0; | ||
connectionInfo[/* retainedState */0] = state$1; | ||
Extension$ReductiveDevTools.send(connectionInfo[/* connection */2], Utilities$ReductiveDevTools.Serializer[/* serializeAction */1](action), Utilities$ReductiveDevTools.Serializer[/* serializeObject */2](state$1)); | ||
} | ||
@@ -736,2 +630,2 @@ } | ||
exports.componentReducerEnhancer = componentReducerEnhancer; | ||
/* serializeMaybeVariant Not a pure module */ | ||
/* evalMethod Not a pure module */ |
{ | ||
"name": "reductive-dev-tools", | ||
"version": "0.1.8", | ||
"version": "0.2.0", | ||
"description": "reductive and reason-react reducer component integration with Redux DevTools", | ||
@@ -5,0 +5,0 @@ "main": "lib/js/src/reductiveDevTools.bs.js", |
@@ -18,4 +18,5 @@ ## reductive-dev-tools | ||
1. Add `-bs-g` into `"bsc-flags"` of your **bsconfig.json** to have variant and record field names available inside extension. | ||
2. Prefer variants with associated data to plain (`SomeAction(unit)` to `SomeAction`) since plain varaints do no carry debug metedata with them (represented as numbers in js) | ||
2. Prefer variants with constructors to plain (`SomeAction(unit)` to `SomeAction`) since plain varaints do no carry debug metedata with them (represented as numbers in js) | ||
3. Extension will be locked (newly dispatched actions will be ignored) when you jump back in action history. | ||
4. Records inside variants do not carry debug metadata in bucklescript yet, if needed you can tag them manually. See [Additional Tagging](https://github.com/ambientlight/reductive-dev-tools#additional-tagging) | ||
@@ -129,3 +130,45 @@ ## Supported DevTools Features | ||
## Additional Tagging | ||
You can also manually customize serialized objects keys and action names displayed inside extension. | ||
Two common usecases: | ||
1. Labeling variants with constructors. | ||
```reason | ||
type routerActions = [ | ||
| `RouterLocationChanged(list(string), string, string) | ||
]; | ||
open ReductiveDevTools.Utilities; | ||
Reductive.Store.dispatch(store, | ||
`RouterLocationChanged(url.path, url.hash, url.search) | ||
|. labelVariant([|"path", "hash", "search"|])); | ||
``` | ||
2. Labeling record keys for records inside variants (since Records inside variants do not carry debug metadata in bucklescript yet). | ||
```reason | ||
type url = { | ||
path: list(string), | ||
hash: string, | ||
search: string, | ||
}; | ||
type routerActions = [ | ||
| `RouterLocationChanged(url) | ||
]; | ||
open ReductiveDevTools.Utilities; | ||
Reductive.Store.dispatch(store, | ||
`RouterLocationChanged(url | ||
|. tagRecord([|"path", "hash", "search"|])); | ||
``` | ||
And(if really needed) you can override bucklescript debug metadata. Please refer to following definitions in `Utilities`: | ||
```reason | ||
let tagVariant: ('a, string) => 'a; | ||
let tagPolyVar: ('a, string) => 'a; | ||
let tagRecord: ('a, array(string)) => 'a; | ||
``` | ||
## Word Of Caution | ||
Current implementation depends on internal bucklescript representation of debug metadata and variants in js. Changes to it in future may silently break the extension. |
Sorry, the diff of this file is not supported yet
115906
12
1154
173