elm-monitor
Version:
Monitor your elm program with redux-devtools
3 lines (2 loc) • 1.12 kB
JavaScript
const{Elm:e}=require("./parser"),n=e=>"string"==typeof e&&/^⟨.+⟩$/.test(e),t=e=>{if(n(e))return[e];const[o,r,...s]=e;if(!n(o))throw Error("`a` not a type string");return n(r)&&0===s.length?[`${o}:${r}`]:Array.isArray(r)&&n(r[0])&&r.length<=2&&0===s.length?t([`${o}:${r[0]}`,...r.slice(1)]):[o,r,...s]},o=n=>new Promise((t,o)=>{const r=e.Main.init(),s=e=>{"Ok"in e?t(e.Ok):o(e.Err),r.ports.sendParsedData.unsubscribe(s)};r.ports.sendParsedData.subscribe(s),r.ports.listenToInput.send(n)});export default()=>{if(window.__REDUX_DEVTOOLS_EXTENSION__&&window.console){const e=window.__REDUX_DEVTOOLS_EXTENSION__.connect({features:{pause:!0,export:!0}}),n=window.console.log.bind(window.console);window.console.log=(...r)=>{const s="string"==typeof r[0]&&r[0].match(/^\[Monitor:(init|update)\]: (.+)$/);if(s){const[,n,r]=s;switch(n){case"init":o(r).then(n=>{e.init(n)},e=>{console.error(e)});break;case"update":o(r).then(([n,o])=>{e.send((e=>{const[n,...o]=t(e);return o.length>0?{type:n+"*",payload:o.length>1?o:o[0]}:{type:n}})(n),o)},e=>{console.error(e)})}}else n(...r)}}};
//# sourceMappingURL=index.modern.js.map