(initialOptions = {})
| 26 | |
| 27 | // creates the app |
| 28 | export const createApp = (initialOptions = {}) => { |
| 29 | // let element |
| 30 | let originalElement = null; |
| 31 | |
| 32 | // get default options |
| 33 | const defaultOptions = getOptions(); |
| 34 | |
| 35 | // create the data store, this will contain all our app info |
| 36 | const store = createStore( |
| 37 | // initial state (should be serializable) |
| 38 | createInitialState(defaultOptions), |
| 39 | |
| 40 | // queries |
| 41 | [queries, createOptionQueries(defaultOptions)], |
| 42 | |
| 43 | // action handlers |
| 44 | [actions, createOptionActions(defaultOptions)] |
| 45 | ); |
| 46 | |
| 47 | // set initial options |
| 48 | store.dispatch('SET_OPTIONS', { options: initialOptions }); |
| 49 | |
| 50 | // kick thread if visibility changes |
| 51 | const visibilityHandler = () => { |
| 52 | if (document.hidden) return; |
| 53 | store.dispatch('KICK'); |
| 54 | } |
| 55 | document.addEventListener('visibilitychange', visibilityHandler); |
| 56 | |
| 57 | // re-render on window resize start and finish |
| 58 | let resizeDoneTimer = null; |
| 59 | let isResizing = false; |
| 60 | let isResizingHorizontally = false; |
| 61 | let initialWindowWidth = null; |
| 62 | let currentWindowWidth = null; |
| 63 | const resizeHandler = () => { |
| 64 | if (!isResizing) { |
| 65 | isResizing = true; |
| 66 | } |
| 67 | clearTimeout(resizeDoneTimer); |
| 68 | resizeDoneTimer = setTimeout(() => { |
| 69 | isResizing = false; |
| 70 | initialWindowWidth = null; |
| 71 | currentWindowWidth = null; |
| 72 | if (isResizingHorizontally) { |
| 73 | isResizingHorizontally = false; |
| 74 | store.dispatch('DID_STOP_RESIZE'); |
| 75 | } |
| 76 | }, 500); |
| 77 | }; |
| 78 | window.addEventListener('resize', resizeHandler); |
| 79 | |
| 80 | // render initial view |
| 81 | const view = root(store, { id: getUniqueId() }); |
| 82 | |
| 83 | // |
| 84 | // PRIVATE API ------------------------------------------------------------------------------------- |
| 85 | // |
no test coverage detected