<commit_before>const localforage = require('localforage')
const run = require('run-auto')

function applyMiddleware(app, done) {
	run({
		onStateChange: function (cb) {
			applyOnStateChange(app, cb)
		},
		wrapInitialState: function (cb) {
			applyWrapInitialState(app, cb)
		}
	}, function (err) {
		return done(err, app)
	})
}

if (inDev()) {
	window.$clearLocalState = function () {
		localforage.setItem('localState', '{}')
	}
}

function applyWrapInitialState(app, done) {
	localforage.getItem('localState', function (err, data) {
		if (err) {
			return done(err)
		}
		app.use({
			wrapInitialState: function (initialState) {
				if (!data) {
					return initialState
				}
				const localState = JSON.parse(data)
				Object.keys(initialState).forEach(function (stateKey) {
					initialState[stateKey] = Object.assign(
						initialState[stateKey],
						localState[stateKey]
					)
				})
				return initialState
			}
		})
		done()
	})<commit_msg>let choo handle location<commit_after>const localforage = require('localforage')
const run = require('run-auto')

function applyMiddleware(app, done) {
	run({
		onStateChange: function (cb) {
			applyOnStateChange(app, cb)
		},
		wrapInitialState: function (cb) {
			applyWrapInitialState(app, cb)
		}
	}, function (err) {
		return done(err, app)
	})
}

if (inDev()) {
	window.$clearLocalState = function () {
		localforage.setItem('localState', '{}')
	}
}

function applyWrapInitialState(app, done) {
	localforage.getItem('localState', function (err, data) {
		if (err) {
			return done(err)
		}
		app.use({
			wrapInitialState: function (initialState) {
				if (!data) {
					return initialState
				}
				const localState = JSON.parse(data)
				Object.keys(initialState).forEach(function (stateKey) {
					if (stateKey === 'location') {
						return
					}
					initialState[stateKey] = Object.assign(
						initialState[stateKey],
						localState[stateKey]
					)
				})
				return initialState
			}
		})
		done()
	})
{'fraction_non_alphanumeric': 0.14011127971674253, 'fraction_numerical': 0.0, 'mean_word_length': 3.63231850117096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324314', 'n_tokens_mistral': 793, 'n_tokens_neox': 661, 'n_words': 129}