Created
February 17, 2017 22:18
-
-
Save vojtatranta/049ac1adf0f06cd6c67fc5614aa9c2d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tohle je prostě entry point pro kód buďto webovej nebo nativní - můžeš udělat kolik endpointů chceš pro jako platformu | |
import * as actions from './actions' | |
import { createStore } from 'redux' | |
// v native-entry.js si requirneš jinej router prostě, zbytek bude prakticky stejnej | |
import Router from 'router' | |
import routes from 'routes' | |
import { Provider } from 'redux-react' | |
Router.config({ routes }) | |
let route = window.location.path | |
const store = crateStore({ | |
'route':route, | |
}) | |
// při změně routy si jí nastav i do storu | |
store.addChangeListener(() => { | |
const storeRoute = store.getState().route | |
if (route !== storeRoute) { | |
route = storeRoute | |
Router.transitionTo(storeRoute) | |
} | |
}) | |
// statická funkce, může se importovat kamkoliv | |
const zmenRoute = (route) => { | |
store.dispatch('ROUTE_CHANGE', route) | |
} | |
// user může změnít routu, je třeba je držet synchrnozizované, novej react-router používá proops kde si předává aktuální cestu | |
Router.history.onPushState((history) => { | |
zmenRoute(history.path) | |
}) | |
export default const App = () => { | |
return ( | |
<Provider store={store}> | |
{Router.run(store.getState().route)} | |
</Provider>) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment