├── .babelrc ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE.txt ├── Makefile ├── README.md ├── package.json └── src └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "michaelcontento" ] 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "michaelcontento" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build artefacts 2 | lib/ 3 | 4 | # npm 5 | node_modules/ 6 | npm-debug.log 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # keep the npm package as small as possible 2 | .babelrc 3 | .editorconfig 4 | .eslintrc 5 | .travis.yml 6 | Makefile 7 | 8 | # we ship lib/ after `make build` 9 | src/ 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.2" 4 | - "4.1" 5 | - "4.0" 6 | - "0.12" 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Michael Contento 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BIN := ./node_modules/.bin 2 | NPM := npm --loglevel=error 3 | 4 | # 5 | # INSTALL 6 | # 7 | 8 | install: node_modules/ 9 | 10 | node_modules/: package.json 11 | $(NPM) --ignore-scripts install 12 | touch node_modules/ 13 | 14 | # 15 | # BUILD 16 | # 17 | 18 | build: clean install 19 | $(BIN)/babel ./src --out-dir ./lib 20 | 21 | # 22 | # CLEAN 23 | # 24 | 25 | clean: 26 | rm -rf ./lib 27 | 28 | mrproper: clean 29 | rm -rf ./node_modules 30 | 31 | # 32 | # TEST 33 | # 34 | 35 | lint: install 36 | $(BIN)/eslint src 37 | 38 | ci: lint build 39 | 40 | # 41 | # MAKEFILE 42 | # 43 | 44 | .PHONY: \ 45 | install \ 46 | build \ 47 | clean mrproper \ 48 | lint ci 49 | 50 | .SILENT: 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [redux-middleware-react-native-appstate][] 2 | ========================================== 3 | 4 | [![license](https://img.shields.io/npm/l/redux-middleware-react-native-appstate.svg?style=flat-square)](https://www.npmjs.com/package/redux-middleware-react-native-appstate) 5 | [![npm version](https://img.shields.io/npm/v/redux-middleware-react-native-appstate.svg?style=flat-square)](https://www.npmjs.com/package/redux-middleware-react-native-appstate) 6 | [![npm downloads](https://img.shields.io/npm/dm/redux-middleware-react-native-appstate.svg?style=flat-square)](https://www.npmjs.com/package/redux-middleware-react-native-appstate) 7 | [![Code Climate](https://codeclimate.com/github/michaelcontento/redux-middleware-react-native-appstate/badges/gpa.svg)](https://codeclimate.com/github/michaelcontento/redux-middleware-react-native-appstate) 8 | [![build](https://travis-ci.org/michaelcontento/redux-middleware-react-native-appstate.svg)](https://travis-ci.org/michaelcontento/redux-middleware-react-native-appstate) 9 | 10 | Glue [AppState][] from [react-native][] to [Redux][]. 11 | 12 | # Deprecated - No longer maintained 13 | 14 | My focus has left the node / react ecosystem and this module is no 15 | longer maintained. 16 | 17 | Thank you for your patience and using this module in the first place! 18 | 19 | ## Installation 20 | 21 | npm install --save redux-middleware-react-native-appstate 22 | 23 | ## Usage 24 | 25 | ```js 26 | // Just import the middleware and add it to your store 27 | import { createStore, applyMiddleware } from 'redux'; 28 | import { middleware as appState } from 'redux-middleware-react-native-appstate'; 29 | const createStoreWithMiddleware = applyMiddleware(appState)(createStore); 30 | 31 | // And in your reducers receive the value 32 | import { TYPE as APP_STATE } from 'redux-middleware-react-native-appstate'; 33 | 34 | function appStateReducer(state = {}, action) { 35 | switch (action.type) { 36 | case APP_STATE: 37 | console.log('AppState:', action.payload); 38 | 39 | default: 40 | return state; 41 | } 42 | } 43 | 44 | ``` 45 | 46 | ## Todo 47 | 48 | - Write tests for everything! 49 | 50 | [Redux]: https://github.com/gaearon/redux 51 | [redux-middleware-react-native-appstate]: https://github.com/michaelcontento/redux-middleware-react-native-appstate 52 | [react-native]: https://facebook.github.io/react-native/ 53 | [AppState]: https://facebook.github.io/react-native/docs/appstateios.html#content 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redux-middleware-react-native-appstate", 3 | "version": "0.0.5", 4 | "description": "Glue AppState from react-native to Redux.", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "make ci", 8 | "prepublish": "make build lint" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/michaelcontento/redux-middleware-react-native-appstate.git" 13 | }, 14 | "homepage": "https://github.com/michaelcontento/redux-middleware-react-native-appstate", 15 | "keywords": [ 16 | "redux", 17 | "redux-middleware", 18 | "middleware", 19 | "react-native", 20 | "fsa", 21 | "flux-standard-action", 22 | "flux" 23 | ], 24 | "author": { 25 | "name": "Michael Contento", 26 | "email": "michaelcontento@gmail.com" 27 | }, 28 | "license": "MIT", 29 | "devDependencies": { 30 | "babel-cli": "^6.1.18", 31 | "babel-eslint": "^4.1.5", 32 | "babel-preset-michaelcontento": "^1.0.0", 33 | "eslint": "^1.9.0", 34 | "eslint-config-airbnb": "^1.0.2", 35 | "eslint-config-michaelcontento": "^1.0.0", 36 | "eslint-plugin-mocha-only": "0.0.3" 37 | }, 38 | "dependencies": { 39 | "react-native": "^0.15.0", 40 | "redux-actions": "^0.8.0", 41 | "redux-middleware-oneshot": "^0.1.1" 42 | }, 43 | "peerDependencies": { 44 | "redux": "^3.0.0 || ^2.0.0 || ^1.0.0 || 1.0.0-alpha || 1.0.0-rc" 45 | }, 46 | "bugs": { 47 | "url": "https://github.com/michaelcontento/redux-middleware-react-native-appstate/issues" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { createAction } from 'redux-actions'; 2 | import createOneShotMiddleware from 'redux-middleware-oneshot'; 3 | import { AppStateIOS } from 'react-native'; 4 | 5 | export const TYPE = 'REDUX_MIDDLEWARE_REACT_NATIVE_APPSTATE'; 6 | export const action = createAction(TYPE); 7 | export const middleware = createOneShotMiddleware((dispatch) => { 8 | const handle = (state) => dispatch(action(state.toLowerCase())); 9 | handle(AppStateIOS.currentState); 10 | AppStateIOS.addEventListener('change', handle); 11 | }); 12 | --------------------------------------------------------------------------------