UNPKG

elm-monitor

Version:

Monitor your elm program with redux-devtools

3 lines (2 loc) 1.28 kB
var n=require("./parser").Elm,t=function(n){return"string"==typeof n&&/^⟨.+⟩$/.test(n)},e=function(n){var e=function n(e){if(t(e))return[e];var r=e[0],o=e[1],i=e.slice(2);if(!t(r))throw Error("`a` not a type string");return t(o)&&0===i.length?[r+":"+o]:Array.isArray(o)&&t(o[0])&&o.length<=2&&0===i.length?n([r+":"+o[0]].concat(o.slice(1))):[r,o].concat(i)}(n),r=e[0],o=e.slice(1);return o.length>0?{type:r+"*",payload:o.length>1?o:o[0]}:{type:r}},r=function(t){return new Promise(function(e,r){var o=n.Main.init();o.ports.sendParsedData.subscribe(function n(t){"Ok"in t?e(t.Ok):r(t.Err),o.ports.sendParsedData.unsubscribe(n)}),o.ports.listenToInput.send(t)})};export default function(){if(window.__REDUX_DEVTOOLS_EXTENSION__&&window.console){var n=window.__REDUX_DEVTOOLS_EXTENSION__.connect({features:{pause:!0,export:!0}}),t=window.console.log.bind(window.console);window.console.log=function(){var o=[].slice.call(arguments),i="string"==typeof o[0]&&o[0].match(/^\[Monitor:(init|update)\]: (.+)$/);if(i){var s=i[1],a=i[2];switch(s){case"init":r(a).then(function(t){n.init(t)},function(n){console.error(n)});break;case"update":r(a).then(function(t){var r=t[1];n.send(e(t[0]),r)},function(n){console.error(n)})}}else t.apply(void 0,o)}}} //# sourceMappingURL=index.esm.js.map