reductive-dev-tools
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -5,4 +5,2 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE | ||
var $$Array = require("bs-platform/lib/js/array.js"); | ||
var Curry = require("bs-platform/lib/js/curry.js"); | ||
var Js_dict = require("bs-platform/lib/js/js_dict.js"); | ||
var Js_types = require("bs-platform/lib/js/js_types.js"); | ||
@@ -12,19 +10,13 @@ var Belt_Array = require("bs-platform/lib/js/belt_Array.js"); | ||
var Belt_Option = require("bs-platform/lib/js/belt_Option.js"); | ||
var Caml_option = require("bs-platform/lib/js/caml_option.js"); | ||
var Js_mapperRt = require("bs-platform/lib/js/js_mapperRt.js"); | ||
var Caml_primitive = require("bs-platform/lib/js/caml_primitive.js"); | ||
var Caml_exceptions = require("bs-platform/lib/js/caml_exceptions.js"); | ||
function unwrap(opt, exc) { | ||
if (opt !== undefined) { | ||
return Caml_option.valFromOption(opt); | ||
} else { | ||
throw exc; | ||
} | ||
(( | ||
function(key){ return Symbol(key) } | ||
)); | ||
function getValue(obj, symbol) { | ||
return obj[symbol]; | ||
} | ||
var create = ( | ||
function(key){ return Symbol(key) } | ||
); | ||
function setValue(obj, symbol, value) { | ||
@@ -49,27 +41,7 @@ Object.defineProperty(obj, symbol, { | ||
var UnexpectedSerializedVariantKey = Caml_exceptions.create("Utilities-ReductiveDevTools.Serializer.Exceptions.UnexpectedSerializedVariantKey"); | ||
var jsMapperConstantArray = /* array */[/* tuple */[ | ||
869834347, | ||
"Symbol(name)" | ||
]]; | ||
var PolyVarTagNotPresentWhileExpected = Caml_exceptions.create("Utilities-ReductiveDevTools.Serializer.Exceptions.PolyVarTagNotPresentWhileExpected"); | ||
var UnexpectedActionType = Caml_exceptions.create("Utilities-ReductiveDevTools.Serializer.Exceptions.UnexpectedActionType"); | ||
var jsMapperConstantArray = /* array */[ | ||
/* tuple */[ | ||
-205812214, | ||
"Symbol(BsPolyVar)" | ||
], | ||
/* tuple */[ | ||
531017570, | ||
"Symbol(BsRecord)" | ||
], | ||
/* tuple */[ | ||
653843305, | ||
"Symbol(ReductiveDevToolsBsLabeledVariant)" | ||
], | ||
/* tuple */[ | ||
1041874580, | ||
"Symbol(BsVariant)" | ||
] | ||
]; | ||
function ofReasonAction(action) { | ||
@@ -80,3 +52,3 @@ var symbols = getOwnPropertySymbols(action); | ||
idx, | ||
"" + (String(symbol) + "") | ||
symbol.toString() | ||
]; | ||
@@ -95,3 +67,3 @@ }), symbols); | ||
param[0], | ||
Js_mapperRt.revSearch(4, jsMapperConstantArray, param[1]) | ||
Js_mapperRt.revSearch(1, jsMapperConstantArray, param[1]) | ||
]; | ||
@@ -112,423 +84,42 @@ }), extractedSymbols), (function (param) { | ||
var jsMapperConstantArray$1 = /* array */[ | ||
/* tuple */[ | ||
-1027084226, | ||
"VariantC" | ||
], | ||
/* tuple */[ | ||
-88365048, | ||
"PolyVarC" | ||
], | ||
/* tuple */[ | ||
4099528, | ||
"Raw" | ||
], | ||
/* tuple */[ | ||
847309489, | ||
"Record" | ||
] | ||
]; | ||
function tToJs(param) { | ||
return Js_mapperRt.binarySearch(4, param, jsMapperConstantArray$1); | ||
} | ||
function tFromJs(param) { | ||
return Js_mapperRt.revSearch(4, jsMapperConstantArray$1, param); | ||
} | ||
function fromReasonAction(action) { | ||
var match = Belt_Array.get(ofReasonAction(action), 0); | ||
if (match !== undefined) { | ||
var match$1 = match[1]; | ||
if (match$1 !== -205812214) { | ||
if (match$1 !== 531017570) { | ||
if (match$1 !== 1041874580) { | ||
return /* Raw */4099528; | ||
} else { | ||
return /* VariantC */-1027084226; | ||
} | ||
} else if (Array.isArray(action)) { | ||
return /* Record */847309489; | ||
} else { | ||
return /* Raw */4099528; | ||
} | ||
} else { | ||
return /* PolyVarC */-88365048; | ||
} | ||
} else { | ||
return /* Raw */4099528; | ||
} | ||
} | ||
var Type = { | ||
tToJs: tToJs, | ||
tFromJs: tFromJs, | ||
fromReasonAction: fromReasonAction | ||
}; | ||
function fromReasonAction$1(action) { | ||
var actionType = fromReasonAction(action); | ||
var userMeta = symbolValue(action, /* DevToolsBsLabeledVariant */653843305); | ||
if (actionType >= 4099528) { | ||
if (actionType >= 847309489) { | ||
var tmp = { | ||
kind: Js_mapperRt.binarySearch(4, actionType, jsMapperConstantArray$1) | ||
}; | ||
var tmp$1 = symbolValue(action, /* BsRecord */531017570); | ||
if (tmp$1 !== undefined) { | ||
tmp.recordKeys = Caml_option.valFromOption(tmp$1); | ||
} | ||
return tmp; | ||
} else { | ||
var tmp$2 = { | ||
kind: Js_mapperRt.binarySearch(4, actionType, jsMapperConstantArray$1), | ||
rawValue: action | ||
}; | ||
if (userMeta !== undefined) { | ||
tmp$2.userMeta = Caml_option.valFromOption(userMeta); | ||
} | ||
return tmp$2; | ||
} | ||
} else if (actionType >= -88365048) { | ||
var tmp$3 = { | ||
kind: Js_mapperRt.binarySearch(4, actionType, jsMapperConstantArray$1) | ||
}; | ||
var tmp$4 = Belt_Array.get(action, 0); | ||
if (tmp$4 !== undefined) { | ||
tmp$3.polyVarTag = Caml_option.valFromOption(tmp$4); | ||
} | ||
var tmp$5 = Js_dict.get(action, "tag"); | ||
if (tmp$5 !== undefined) { | ||
tmp$3.tag = Caml_option.valFromOption(tmp$5); | ||
} | ||
if (userMeta !== undefined) { | ||
tmp$3.userMeta = Caml_option.valFromOption(userMeta); | ||
} | ||
return tmp$3; | ||
} else { | ||
var tmp$6 = { | ||
kind: Js_mapperRt.binarySearch(4, actionType, jsMapperConstantArray$1) | ||
}; | ||
var tmp$7 = Js_dict.get(action, "tag"); | ||
if (tmp$7 !== undefined) { | ||
tmp$6.tag = Caml_option.valFromOption(tmp$7); | ||
} | ||
if (userMeta !== undefined) { | ||
tmp$6.userMeta = Caml_option.valFromOption(userMeta); | ||
} | ||
return tmp$6; | ||
} | ||
} | ||
function _actionName(action, internals) { | ||
var userMetaName = Belt_Option.flatMap(Caml_option.undefined_to_opt(internals.userMeta), (function (userMeta) { | ||
return Caml_option.undefined_to_opt(userMeta.actionName); | ||
})); | ||
var actionType = fromReasonAction(action); | ||
if (userMetaName !== undefined) { | ||
return userMetaName; | ||
} else if (actionType !== -1027084226) { | ||
if (actionType !== -88365048) { | ||
return "update"; | ||
} else { | ||
return Belt_Option.getWithDefault(symbolValue(action, /* BsPolyVar */-205812214), "update"); | ||
} | ||
} else { | ||
return Belt_Option.getWithDefault(symbolValue(action, /* BsVariant */1041874580), "update"); | ||
} | ||
} | ||
function serializeObject(obj) { | ||
var isList = Belt_Option.map(symbolValue(obj, /* BsVariant */1041874580), (function (variantName) { | ||
return variantName === "::"; | ||
})); | ||
var recordKeys = symbolValue(obj, /* BsRecord */531017570); | ||
var tmp = { | ||
kind: Js_mapperRt.binarySearch(4, /* Raw */4099528, jsMapperConstantArray$1) | ||
}; | ||
if (recordKeys !== undefined) { | ||
tmp.recordKeys = Caml_option.valFromOption(recordKeys); | ||
} | ||
if (isList !== undefined) { | ||
tmp.isList = Caml_option.valFromOption(isList); | ||
} | ||
var base = { | ||
__internal: tmp | ||
}; | ||
var match = Js_types.classify(obj); | ||
var match$1 = fromReasonAction(obj); | ||
var serialized; | ||
if (typeof match === "number" || match.tag !== /* JSObject */3) { | ||
serialized = obj; | ||
} else { | ||
var obj$1 = match[0]; | ||
if (match$1 !== 847309489) { | ||
if (Array.isArray(obj$1)) { | ||
var match$2 = Belt_Option.getWithDefault(isList, false); | ||
var array = match$2 ? $$Array.of_list(obj$1) : obj$1; | ||
serialized = $$Array.map(serializeObject, array); | ||
} else { | ||
serialized = Array.isArray(obj$1) ? obj : Js_dict.map(serializeObject, obj$1); | ||
} | ||
} else { | ||
serialized = _serializeRecordToDict(obj$1); | ||
} | ||
} | ||
var match$3 = Js_types.classify(serialized); | ||
if (typeof match$3 === "number" || match$3.tag !== /* JSObject */3) { | ||
return serialized; | ||
} else { | ||
return Object.assign(base, match$3[0]); | ||
} | ||
} | ||
function _serializeRecordToDict(obj) { | ||
var keys = symbolValue(obj, /* BsRecord */531017570); | ||
if (keys !== undefined) { | ||
var keys$1 = Caml_option.valFromOption(keys); | ||
return Belt_Array.reduceWithIndex(obj, { }, (function (target, value, idx) { | ||
var key = Belt_Array.get(keys$1, idx); | ||
target[Belt_Option.getWithDefault(key, String(idx))] = serializeObject(value); | ||
return target; | ||
})); | ||
} else { | ||
return Object.assign({ }, $$Array.map(serializeObject, obj)); | ||
} | ||
} | ||
function _serializeVariantToDict(action, isPolyVar) { | ||
var keys = Belt_Option.flatMap(symbolValue(action, /* DevToolsBsLabeledVariant */653843305), (function (meta) { | ||
return Caml_option.undefined_to_opt(meta.keys); | ||
})); | ||
if (keys !== undefined) { | ||
var keys$1 = keys; | ||
return Belt_Array.reduceWithIndex(isPolyVar ? Caml_array.caml_array_get(action, 1) : action, { }, (function (target, value, idx) { | ||
var variantKey = Belt_Array.get(keys$1, idx); | ||
target[Belt_Option.getWithDefault(variantKey, String(idx))] = serializeObject(value); | ||
return target; | ||
})); | ||
} else { | ||
return Object.assign({ }, $$Array.map(serializeObject, action)); | ||
} | ||
} | ||
function deserializeObject(obj) { | ||
var isList = Belt_Option.getWithDefault(Belt_Option.flatMap(Caml_option.undefined_to_opt(obj.__internal), (function (prim) { | ||
return Caml_option.undefined_to_opt(prim.isList); | ||
})), false); | ||
var recordKeys = Belt_Option.flatMap(Caml_option.undefined_to_opt(obj.__internal), (function (prim) { | ||
return Caml_option.undefined_to_opt(prim.recordKeys); | ||
})); | ||
var match = Js_types.classify(obj); | ||
if (typeof match === "number" || match.tag !== /* JSObject */3) { | ||
return obj; | ||
} else { | ||
var _objectValue = match[0]; | ||
if (recordKeys !== undefined) { | ||
return _deserializeRecord(obj); | ||
} else { | ||
var deserialized = $$Array.map((function (key) { | ||
return deserializeObject(_objectValue[key]); | ||
}), Belt_Array.keep(Object.keys(_objectValue), (function (key) { | ||
return key !== "__internal"; | ||
}))); | ||
var deserialized$1 = isList ? $$Array.to_list(deserialized) : deserialized; | ||
if (isList) { | ||
setValue(deserialized$1, Curry._1(create, "BsVariant"), "::"); | ||
} | ||
return deserialized$1; | ||
} | ||
} | ||
} | ||
function _deserializeRecord(obj) { | ||
var recordKeys = Belt_Option.flatMap(Caml_option.undefined_to_opt(obj.__internal), (function (prim) { | ||
return Caml_option.undefined_to_opt(prim.recordKeys); | ||
})); | ||
var deserialized = $$Array.map((function (key) { | ||
return deserializeObject(obj[key]); | ||
}), Belt_Array.keep(Object.keys(obj), (function (key) { | ||
return key !== "__internal"; | ||
}))); | ||
if (recordKeys !== undefined) { | ||
setValue(deserialized, Curry._1(create, "BsRecord"), recordKeys); | ||
} | ||
return deserialized; | ||
} | ||
function serializeAction(action) { | ||
var action$1 = action; | ||
var internal = fromReasonAction$1(action$1); | ||
var actionName = _actionName(action$1, internal); | ||
var base = { | ||
type: actionName, | ||
__internal: internal | ||
}; | ||
var match = fromReasonAction(action$1); | ||
if (match >= 4099528) { | ||
if (match >= 847309489) { | ||
return Object.assign(base, _serializeRecordToDict(action$1)); | ||
} else { | ||
return base; | ||
} | ||
} else if (match >= -88365048) { | ||
return Object.assign(base, _serializeVariantToDict(action$1, true)); | ||
} else { | ||
return Object.assign(base, _serializeVariantToDict(action$1, false)); | ||
} | ||
return Belt_Option.getWithDefault(Belt_Option.map(symbolValue(action$1, /* Name */869834347), (function (actionName) { | ||
var base = { | ||
type: actionName | ||
}; | ||
return Object.assign(base, action$1); | ||
})), action$1); | ||
} | ||
var serializeObject$1 = serializeObject; | ||
function deserializeAction(action) { | ||
var action$1 = action; | ||
var internal = action$1.__internal; | ||
var param = internal.kind; | ||
var actionType = Belt_Option.getWithDefault(Js_mapperRt.revSearch(4, jsMapperConstantArray$1, param), /* Raw */4099528); | ||
if (actionType !== 4099528) { | ||
if (actionType >= 847309489) { | ||
return _deserializeRecord(action$1); | ||
} else { | ||
var action$2 = action$1; | ||
var actionType$1 = actionType; | ||
var internal$1 = action$2.__internal; | ||
var keys = Belt_Option.flatMap(Caml_option.undefined_to_opt(internal$1.userMeta), (function (userMeta) { | ||
return Caml_option.undefined_to_opt(userMeta.keys); | ||
})); | ||
var varTag = internal$1.tag; | ||
var polyVarTag = internal$1.polyVarTag; | ||
var deserialized; | ||
if (keys !== undefined) { | ||
var keys$1 = keys; | ||
deserialized = $$Array.fold_left((function (deserialized, key) { | ||
var idx = keys$1.findIndex((function (entity) { | ||
return entity === key; | ||
})); | ||
if (idx === -1) { | ||
throw [ | ||
UnexpectedSerializedVariantKey, | ||
"Serialized variant key(" + (String(key) + ") corresponding array idx has not been found.") | ||
]; | ||
} | ||
Caml_array.caml_array_set(deserialized, idx, action$2[key]); | ||
return deserialized; | ||
}), new Array(keys$1.length), Belt_Array.keep(Object.keys(action$2), (function (key) { | ||
if (key !== "__internal") { | ||
return key !== "type"; | ||
} else { | ||
return false; | ||
} | ||
}))); | ||
} else { | ||
deserialized = $$Array.map((function (key) { | ||
return deserializeObject(action$2[key]); | ||
}), Belt_Array.keep(Object.keys(action$2), (function (key) { | ||
if (key !== "__internal") { | ||
return key !== "type"; | ||
} else { | ||
return false; | ||
} | ||
}))); | ||
} | ||
var actionTypeStr = Js_mapperRt.binarySearch(4, actionType$1, jsMapperConstantArray$1); | ||
if (actionType$1 !== -1027084226) { | ||
if (actionType$1 !== -88365048) { | ||
throw [ | ||
UnexpectedActionType, | ||
"" + (String(actionTypeStr) + "") | ||
]; | ||
} | ||
var polyVarTag$1 = unwrap(polyVarTag === undefined ? undefined : Caml_option.some(polyVarTag), [ | ||
PolyVarTagNotPresentWhileExpected, | ||
"PolyVar tag not present while expected" | ||
]); | ||
var deserialized$1; | ||
if (keys !== undefined) { | ||
var deserialized$2 = /* array */[ | ||
polyVarTag$1, | ||
deserialized | ||
]; | ||
setValue(deserialized$2, Curry._1(create, "ReductiveDevToolsBsLabeledVariant"), Caml_option.undefined_to_opt(internal$1.userMeta)); | ||
deserialized$1 = deserialized$2; | ||
} else { | ||
Caml_array.caml_array_set(deserialized, 0, polyVarTag$1); | ||
deserialized$1 = deserialized; | ||
} | ||
setValue(deserialized$1, Curry._1(create, "BsPolyVar"), action$2.type); | ||
return deserialized$1; | ||
} else { | ||
setValue(deserialized, Curry._1(create, "BsVariant"), action$2.type); | ||
if (varTag !== undefined) { | ||
deserialized["tag"] = varTag; | ||
return deserialized; | ||
} else { | ||
return deserialized; | ||
} | ||
} | ||
} | ||
} else { | ||
return Belt_Option.getExn(Caml_option.undefined_to_opt(internal.rawValue)); | ||
} | ||
return action; | ||
} | ||
var deserializeObject$1 = deserializeObject; | ||
function labelVariant(variant, keys) { | ||
setValue(variant, Curry._1(create, "ReductiveDevToolsBsLabeledVariant"), { | ||
keys: keys | ||
}); | ||
return variant; | ||
function Symbol_toString(prim) { | ||
return prim.toString(); | ||
} | ||
function tagVariant(variant, name) { | ||
setValue(variant, Curry._1(create, "BsVariant"), name); | ||
return variant; | ||
} | ||
var $$Symbol = { | ||
getValue: getValue, | ||
setValue: setValue, | ||
toString: Symbol_toString | ||
}; | ||
function tagList(list) { | ||
var match = Js_types.classify(list); | ||
if (typeof match === "number" || match.tag !== /* JSObject */3) { | ||
return list; | ||
} else { | ||
return tagVariant(list, "::"); | ||
} | ||
} | ||
var Serializer_DebugSymbol = { | ||
ofReasonAction: ofReasonAction, | ||
symbolValue: symbolValue | ||
}; | ||
function tagPolyVar(polyVar, name) { | ||
setValue(polyVar, Curry._1(create, "BsPolyVar"), name); | ||
return polyVar; | ||
} | ||
var Serializer_Action = { }; | ||
function tagRecord(obj, keys) { | ||
setValue(obj, Curry._1(create, "BsRecord"), keys); | ||
return obj; | ||
} | ||
function parse(prim) { | ||
return JSON.parse(prim); | ||
} | ||
var Serializer_Action = { | ||
Type: Type, | ||
UserMeta: { }, | ||
Internals: { } | ||
}; | ||
var Serializer = { | ||
DebugSymbol: Serializer_DebugSymbol, | ||
Action: Serializer_Action, | ||
serializeAction: serializeAction, | ||
serializeObject: serializeObject$1, | ||
deserializeAction: deserializeAction, | ||
deserializeObject: deserializeObject$1 | ||
deserializeAction: deserializeAction | ||
}; | ||
exports.unwrap = unwrap; | ||
exports.parse = parse; | ||
exports.$$Symbol = $$Symbol; | ||
exports.Serializer = Serializer; | ||
exports.labelVariant = labelVariant; | ||
exports.tagList = tagList; | ||
exports.tagVariant = tagVariant; | ||
exports.tagPolyVar = tagPolyVar; | ||
exports.tagRecord = tagRecord; | ||
/* create Not a pure module */ | ||
/* Not a pure module */ |
{ | ||
"name": "reductive-dev-tools", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "reductive and reason-react reducer component integration with Redux DevTools", | ||
@@ -5,0 +5,0 @@ "main": "lib/js/src/reductiveDevTools.bs.js", |
@@ -7,4 +7,7 @@ ## reductive-dev-tools | ||
[reductive](https://github.com/reasonml-community/reductive) and [reason-react](https://github.com/reasonml/reason-react) reducer component integration with [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension) | ||
[reductive](https://github.com/reasonml-community/reductive) and [reason-react](https://github.com/reasonml/reason-react) reducer component integration with [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension). | ||
Requires **bucklescript 8.x.x**, for lower versions of bucklescript, please rely on **2.0.0**. | ||
![image](assets/demo.gif) | ||
@@ -66,2 +69,3 @@ | ||
#### Usage with ReactReason legacy reducer component (jsx2) | ||
No longer supported. Please install latest from 0.x: | ||
@@ -78,3 +82,3 @@ | ||
### Actions | ||
[redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension) uses value under `type` key of action object for its name in the monitor. Most likely you are going to use [variants](https://reasonml.github.io/docs/en/variant) for actions, which need to be serialized into js objects to be usefully displayed inside the extension. Actions serialization is built-in. As an alternative, you can override default serializer by passing `~actionSerializer` like: | ||
With bucklescript 8 release, variants are js-objects at runtime, so this extension no longer serializes actions. By default it only extracts variant name from `Symbol(name)` when `-bs-g` flag is set in `bsconfig.json`. If needed, you can define your custom serialization by passing `~actionSerializer` like: | ||
@@ -103,4 +107,2 @@ ```reason | ||
2. Variants with constructors should be prefered to plain (`SomeAction(unit)` to `SomeAction`) since plain varaints do no carry debug metedata(in symbols) with them (represented as numbers in js). | ||
3. Action names won't be displayed when using [extensible variants](https://caml.inria.fr/pub/docs/manual-ocaml/manual037.html#sec269), they also do not carry debug metadata. [Extensible variant name becomes "update"](https://github.com/ambientlight/reductive-dev-tools/issues/2) | ||
4. Records inside variants do not carry debug metadata in bucklescript yet, if needed you can tag them manually. See [Additional Tagging](#additional-tagging). | ||
@@ -167,38 +169,2 @@ ### State | ||
()) | ||
``` | ||
## 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"|])); | ||
``` | ||
This can also be used to override bucklescript debug metadata(if really needed). Definitions are at: [utilities.rei](https://github.com/ambientlight/reductive-dev-tools/blob/a530ea6d09d7facad2b70c061703eff52cfa80b4/src/utilities.rei#L63-L67) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
56804
442
165