import './main.sass'
import 'babel-polyfill'
import 'isomorphic-fetch'

import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { Router } from 'react-router'
import { updateStrings as updateTimeAgoStrings } from './vendor/time_ago_in_words'
import { persistStore } from 'redux-persist'
import localforage from 'localforage'
import store from './store'
import { browserHistory } from 'react-router'
import routes from './routes'

import './vendor/embetter'
import './vendor/embetter_initializer'

updateTimeAgoStrings({ about: '' })

const element = (
  <Provider store={store}>
    <Router history={browserHistory} routes={routes} />
  </Provider>
)

const storage = localforage.createInstance({ name: 'ello-webapp' })
const whitelist = ['authentication', 'editor', 'gui', 'json', 'profile']
const persistor = persistStore(store, { storage, whitelist }, () => {
  ReactDOM.render(element, document.getElementById('root'))
})

// check and update current version and
// only kill off the persisted reducers
if (ENV.APP_VERSION) {
  storage.getItem('APP_VERSION')
    .then((curVersion) => {
      if (curVersion && curVersion !== ENV.APP_VERSION) {
        persistor.purge(['json', 'profile'])
      }
      storage.setItem('APP_VERSION', ENV.APP_VERSION)
    })
}



import './main.sass'
import 'babel-polyfill'
import 'isomorphic-fetch'

import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { Router } from 'react-router'
import { updateStrings as updateTimeAgoStrings } from './vendor/time_ago_in_words'
import { persistStore } from 'redux-persist'
import localforage from 'localforage'
import store from './store'
import { browserHistory } from 'react-router'
import routes from './routes'

import './vendor/embetter'
import './vendor/embetter_initializer'

updateTimeAgoStrings({ about: '' })

const APP_VERSION = '1.0.5'

const element = (
  <Provider store={store}>
    <Router history={browserHistory} routes={routes} />
  </Provider>
)

const storage = localforage.createInstance({ name: 'ello-webapp' })
const whitelist = ['authentication', 'editor', 'gui', 'json', 'profile']
const persistor = persistStore(store, { storage, whitelist }, () => {
  ReactDOM.render(element, document.getElementById('root'))
})

// check and update current version and
// only kill off the persisted reducers
storage.getItem('APP_VERSION')
  .then((curVersion) => {
    if (curVersion && curVersion !== APP_VERSION) {
      persistor.purgeAll()
    }
    storage.setItem('APP_VERSION', APP_VERSION)
  })


Move the APP_VERSION into app instead of config.
Move the APP_VERSION into app instead of config.

It felt kinda silly to have to remember to update a config var before pushing up a deploy. This allows us to just modify it in the js and have it purge from one spot. Also allows us the ability to have more logic around what gets purged if we want to be more specific about it in the future, but it purges all for now. this probably won’t need to be updated as much now that we aren’t persisting much data. Would only need to update if we changed the format of authentication, editor, gui, json(deleted arrays for posts/comments/users), or an update to the profile json. Once this gets merged in we can remove the config var APP_VERSION from heroku.