Created
May 11, 2020 16:11
-
-
Save AllGistsEqual/6373510c3d8091ac87a960d28aa2b0fe to your computer and use it in GitHub Desktop.
This file contains 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
import { | |
INIT_APPLICATION, | |
} from '../../actions/application.actions' | |
import manifest from '../../../../app.json' | |
const { expo: { name, version: manifestVersion } } = manifest | |
const applicationMiddleware = ({ getState }) => (next) => (action) => { | |
switch (action.type) { | |
case INIT_APPLICATION: { | |
const { application: { version: oldVersion } } = getState() | |
console.log(`oldVersion: (${oldVersion}) // manifestVersion: (${manifestVersion})`) | |
if (oldVersion === -1 || oldVersion === manifestVersion) { | |
// enrich payload of current action and pass it on with next() | |
next({ | |
...action, | |
payload: { | |
...action.payload, | |
name, | |
version: manifestVersion, | |
}, | |
}) | |
break | |
} | |
// here be code for version updates | |
break | |
} | |
default: { | |
next(action) | |
} | |
} | |
} | |
export default applicationMiddleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment