-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js.map
1 lines (1 loc) · 3.84 KB
/
index.js.map
1
{"version":3,"file":"index.js","sources":["src/actions.js","src/model.js"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport decorate from 'k-mst-purifier'\nimport pathToRegexp from 'path-to-regexp'\n\nexport const afterCreate = self => () => {\n self.init()\n}\n\nexport const go = self => (screenName, params = null) => {\n // get screen reference from name\n const screen = self.screens.find(sc => sc.name === screenName)\n\n // save to the store\n self.current = screen\n self.params = params\n\n // save to the navigator\n const toPath = pathToRegexp.compile(screen.path)\n window.history.pushState(null, screen.name, toPath(params))\n}\n\nexport const init = self => () => {\n const { pathname } = window.location\n\n let found = false\n for (let i = 0; i < self.screens.length && !found; i += 1) {\n const screen = self.screens[i]\n const params = []\n const match = pathToRegexp(screen.path, params, { sensitive: true }).exec(pathname)\n\n found = !!match\n if (found) {\n self.go(\n screen.name,\n params\n .map(({ name }, index) => ({ [name]: match[index + 1] }))\n .reduce(\n (acc, curr) => ({ ...acc, ...curr }),\n {},\n ),\n )\n }\n }\n}\n\nexport default decorate({\n afterCreate,\n go,\n init,\n})\n","import { types } from 'mobx-state-tree'\nimport actions from './actions'\n\nconst ScreenDefinition = types\n .model({\n name: types.identifier(types.string),\n path: types.string,\n })\n .named('ScreenDefinition')\n\nexport default types\n .model({\n screens: types.array(ScreenDefinition),\n params: types.maybe(types.map(types.union(types.string, types.number))),\n current: types.maybe(types.reference(ScreenDefinition)),\n })\n .named('Router')\n .actions(actions)\n // Views:\n // get current (Screen)\n // get params (current.params)\n"],"names":["afterCreate","init","go","screenName","params","screen","self","screens","find","sc","name","current","toPath","pathToRegexp","compile","path","history","pushState","pathname","window","location","found","i","match","sensitive","exec","map","index","reduce","acc","curr","length","decorate","ScreenDefinition","types","model","identifier","string","named","array","maybe","union","number","reference","actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA,AAGO,IAAMA,cAAc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