├── .npmignore ├── src ├── state │ ├── routing-state.ts │ ├── framework7-state.ts │ └── modals-state.ts ├── redux │ ├── reducers │ │ ├── framework7-reducer.ts │ │ ├── routing-reducer.ts │ │ └── modal-reducer.ts │ ├── sync.ts │ ├── actions │ │ ├── routing-actions.ts │ │ ├── modal-actions.ts │ │ └── framework7-actions.ts │ └── selectors │ │ └── history-selectors.ts ├── state-kernels │ ├── framework7-kernel.ts │ ├── modal-kernel.ts │ ├── modals │ │ ├── alert-kernel.ts │ │ ├── confirm-kernel.ts │ │ ├── modal-message-helper.ts │ │ └── preloader-kernel.ts │ ├── routing-kernel.ts │ └── routing │ │ └── history-reconciler.ts ├── index.ts ├── framework7-redux-plugin.ts └── state-kernel.ts ├── .vscode └── settings.json ├── tsconfig.json ├── .gitignore ├── package.json ├── README.md └── LICENSE /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | gulpfile.js 3 | tsconfig.json 4 | src/ 5 | .vscode/ -------------------------------------------------------------------------------- /src/state/routing-state.ts: -------------------------------------------------------------------------------- 1 | export interface IRoutingHistoryState { 2 | [viewName: string]: string[]; 3 | } 4 | 5 | export interface IRoutingState { 6 | history: IRoutingHistoryState; 7 | } -------------------------------------------------------------------------------- /src/state/framework7-state.ts: -------------------------------------------------------------------------------- 1 | import {IModalState} from './modals-state'; 2 | import {IRoutingState} from './routing-state'; 3 | 4 | export interface IFramework7State { 5 | routing: IRoutingState, 6 | modals: IModalState 7 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.DS_Store": true, 6 | "**/typings/": true, 7 | "**/dist/": true, 8 | "**/node_modules/": true 9 | }, 10 | "typescript.tsdk": "./node_modules/typescript/lib" 11 | } -------------------------------------------------------------------------------- /src/state/modals-state.ts: -------------------------------------------------------------------------------- 1 | export interface IModalMessageState { 2 | modalMessageType: 'alert' | 'confirm'; 3 | title: string; 4 | text: string; 5 | } 6 | 7 | export interface IPreloaderState { 8 | visible: boolean; 9 | loadingText?: string; 10 | } 11 | 12 | export interface IModalState { 13 | modalMessage: IModalMessageState; 14 | preloader: IPreloaderState; 15 | } -------------------------------------------------------------------------------- /src/redux/reducers/framework7-reducer.ts: -------------------------------------------------------------------------------- 1 | import {combineReducers, Action} from 'redux'; 2 | 3 | import {IFramework7State} from '../../state/framework7-state'; 4 | import {routingReducer} from './routing-reducer'; 5 | import {modalsReducer} from './modal-reducer'; 6 | 7 | export const framework7Reducer = combineReducers({ 8 | routing: routingReducer, 9 | modals: modalsReducer 10 | }); -------------------------------------------------------------------------------- /src/redux/sync.ts: -------------------------------------------------------------------------------- 1 | import {Store} from 'redux'; 2 | 3 | import {Framework7StateKernel} from '../state-kernels/framework7-kernel'; 4 | 5 | export const syncFramework7WithStore = (store: Store, stateKernel: Framework7StateKernel) => { 6 | store.subscribe(() => { 7 | stateKernel.setState(store.getState()); 8 | }); 9 | 10 | stateKernel.setActionDispatchHandler((action) => { 11 | store.dispatch(action); 12 | }); 13 | }; -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "declaration": true, 5 | "module": "commonjs", 6 | "sourceMap": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "outDir": "dist", 11 | "strict": true, 12 | "strictNullChecks": false, 13 | "rootDir": ".", 14 | "lib": ["es2015", "dom"] 15 | } 16 | } -------------------------------------------------------------------------------- /src/redux/actions/routing-actions.ts: -------------------------------------------------------------------------------- 1 | import {NavigateToAction, GoBackAction} from './framework7-actions'; 2 | 3 | export const navigateTo = (path: string, replace?: boolean, viewName: string = 'main'): NavigateToAction => { 4 | return { 5 | type: '@@FRAMEWORK7_NAVIGATE_TO', 6 | path, 7 | replace, 8 | viewName 9 | }; 10 | }; 11 | 12 | export const goBack = (viewName: string = 'main'): GoBackAction => { 13 | return { 14 | type: '@@FRAMEWORK7_GO_BACK', 15 | viewName 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /src/state-kernels/framework7-kernel.ts: -------------------------------------------------------------------------------- 1 | import {StateKernel} from '../state-kernel'; 2 | import {IFramework7State} from '../state/framework7-state'; 3 | import {RoutingKernel} from './routing-kernel'; 4 | import {ModalKernel} from './modal-kernel'; 5 | 6 | export class Framework7StateKernel extends StateKernel { 7 | constructor(testMode: boolean = false) { 8 | super(testMode); 9 | 10 | this.children = [ 11 | new RoutingKernel(), 12 | new ModalKernel() 13 | ]; 14 | } 15 | 16 | protected handleStateChange() {} 17 | 18 | protected getState(fullState: any) { 19 | return fullState.framework7 as IFramework7State; 20 | } 21 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | dist/ 40 | typings/ 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "framework7-redux", 3 | "version": "3.0.6", 4 | "description": "", 5 | "main": "./dist/src/index.js", 6 | "scripts": { 7 | "build": "tsc" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/bencompton/framework7-redux.git" 12 | }, 13 | "keywords": [ 14 | "framework7", 15 | "react", 16 | "redux", 17 | "typescript" 18 | ], 19 | "author": "Ben Compton", 20 | "license": "APACHE 2.0", 21 | "bugs": { 22 | "url": "https://github.com/bencompton/framework7-redux/issues" 23 | }, 24 | "homepage": "https://github.com/bencompton/framework7-redux#readme", 25 | "dependencies": { 26 | "redux": "3.6.0" 27 | }, 28 | "devDependencies": { 29 | "typescript": "3.5.3" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/state-kernels/modal-kernel.ts: -------------------------------------------------------------------------------- 1 | import { StateKernel } from '../state-kernel'; 2 | import { IModalState } from '../state/modals-state'; 3 | import { IFramework7State } from '../state/framework7-state'; 4 | import { AlertKernel } from './modals/alert-kernel'; 5 | import { PreloaderKernel } from './modals/preloader-kernel'; 6 | import { ConfirmKernel } from './modals/confirm-kernel'; 7 | 8 | export class ModalKernel extends StateKernel { 9 | constructor() { 10 | super(); 11 | 12 | this.children = [ 13 | new AlertKernel(), 14 | new ConfirmKernel(), 15 | new PreloaderKernel() 16 | ] 17 | } 18 | 19 | protected getState(fullState: IFramework7State) { 20 | return fullState.modals; 21 | } 22 | 23 | protected handleStateChange(state: IModalState) {} 24 | } -------------------------------------------------------------------------------- /src/redux/selectors/history-selectors.ts: -------------------------------------------------------------------------------- 1 | const checkState = (state: any) => { 2 | if (!state.framework7 || !state.framework7.routing || !state.framework7.routing.history) { 3 | throw new Error('State must contain a property called "framework7" and must be controlled by the framework7-redux reducer!'); 4 | } 5 | }; 6 | 7 | export const getCurrentRoute = (state: { framework7: any }, viewName: string = 'main') => { 8 | checkState(state); 9 | 10 | return state.framework7.routing.history[viewName][state.framework7.routing.history[viewName].length - 1] as string; 11 | }; 12 | 13 | export const getPreviousRoute = (state: { framework7: any }, viewName: string = 'main') => { 14 | checkState(state); 15 | 16 | return state.framework7.routing.history[viewName][state.framework7.routing.history[viewName].length - 2] as string; 17 | }; -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { Framework7StateKernel } from './state-kernels/framework7-kernel'; 2 | export { 3 | showAlert, 4 | closeAlert, 5 | showPreloader, 6 | hidePreloader, 7 | showConfirm, 8 | acceptConfirm, 9 | cancelConfirm 10 | } from './redux/actions/modal-actions'; 11 | export { navigateTo, goBack } from './redux/actions/routing-actions'; 12 | export { framework7Reducer } from './redux/reducers/framework7-reducer'; 13 | export { IFramework7State } from './state/framework7-state'; 14 | export { syncFramework7WithStore } from './redux/sync'; 15 | export { 16 | ShowAlertAction, CloseAlertAction, ShowPreloaderAction, 17 | HidePreloaderAction, ModalAction, RoutingAction, NavigateToAction, 18 | GoBackAction 19 | } from './redux/actions/framework7-actions'; 20 | export { framework7ReduxPlugin } from './framework7-redux-plugin'; 21 | export { getCurrentRoute, getPreviousRoute } from './redux/selectors/history-selectors'; -------------------------------------------------------------------------------- /src/state-kernels/modals/alert-kernel.ts: -------------------------------------------------------------------------------- 1 | import { closeAlert } from '../../redux/actions/modal-actions'; 2 | import { StateKernel } from '../../state-kernel'; 3 | import { IModalMessageState } from '../../state/modals-state'; 4 | import { ModalMessageHelper } from './modal-message-helper'; 5 | import { IModalState } from '../../state/modals-state'; 6 | 7 | export class AlertKernel extends StateKernel { 8 | private modalMessageHelper: ModalMessageHelper; 9 | 10 | public onFramework7Set(framework7: any) { 11 | this.modalMessageHelper = new ModalMessageHelper(framework7, [{ 12 | text: 'Ok', 13 | onClick: () => this.dispatchAction(closeAlert()) 14 | }]); 15 | } 16 | 17 | protected getState(state: IModalState) { 18 | return state.modalMessage; 19 | } 20 | 21 | protected handleStateChange(state: IModalMessageState) { 22 | if (state.modalMessageType === 'alert') { 23 | this.modalMessageHelper.handleStateChange(state); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/framework7-redux-plugin.ts: -------------------------------------------------------------------------------- 1 | import { StateKernel } from './state-kernel'; 2 | 3 | export const framework7ReduxPlugin = { 4 | name: 'framework7-redux', 5 | on: { 6 | init: function () { 7 | const app: any = this; 8 | 9 | // Make sure links in Framework7 don't change the URL 10 | app.on('click', (e: any) => { 11 | const clicked = app.$(e.target); 12 | const clickedLink = clicked.closest('a'); 13 | const isLink = clickedLink.length > 0; 14 | 15 | if (isLink) { 16 | e.preventDefault(); 17 | } 18 | }); 19 | 20 | if (app.params.stateKernel) { 21 | app.params.stateKernel.setFramework7(app); 22 | } else { 23 | throw new Error('Framework7 Redux plug-in requires a state kernel'); 24 | } 25 | } 26 | }, 27 | install() { 28 | // Nothing to do here 29 | }, 30 | create(instance: any) { 31 | return () => {}; 32 | } 33 | }; -------------------------------------------------------------------------------- /src/state-kernels/modals/confirm-kernel.ts: -------------------------------------------------------------------------------- 1 | import { acceptConfirm, cancelConfirm } from '../../redux/actions/modal-actions'; 2 | import { IModalState, IModalMessageState } from '../../state/modals-state'; 3 | import { ModalMessageHelper } from './modal-message-helper'; 4 | import { StateKernel } from '../../state-kernel'; 5 | 6 | export class ConfirmKernel extends StateKernel { 7 | private modalMessageHelper: ModalMessageHelper; 8 | 9 | public onFramework7Set(framework7: any) { 10 | this.modalMessageHelper = new ModalMessageHelper(framework7, [{ 11 | text: 'Ok', 12 | onClick: () => this.dispatchAction(acceptConfirm()) 13 | }, { 14 | text: 'Cancel', 15 | onClick: () => this.dispatchAction(cancelConfirm()) 16 | }]); 17 | } 18 | 19 | protected getState(state: IModalState) { 20 | return state.modalMessage; 21 | } 22 | 23 | protected handleStateChange(state: IModalMessageState) { 24 | if (state.modalMessageType === 'confirm') { 25 | this.modalMessageHelper.handleStateChange(state); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/redux/reducers/routing-reducer.ts: -------------------------------------------------------------------------------- 1 | import {combineReducers, Reducer} from 'redux'; 2 | import {RoutingAction} from '../actions/framework7-actions'; 3 | import {IRoutingState, IRoutingHistoryState} from '../../state/routing-state'; 4 | 5 | const initialState: IRoutingHistoryState = { 6 | main: [] 7 | }; 8 | 9 | export const historyReducer: Reducer = (state: IRoutingHistoryState = initialState, action: RoutingAction) => { 10 | switch (action.type) { 11 | case '@@FRAMEWORK7_NAVIGATE_TO': 12 | let currentHistory = state[action.viewName] || []; 13 | 14 | if (action.replace) { 15 | currentHistory = currentHistory.slice(0, currentHistory.length - 1); 16 | } 17 | 18 | return { 19 | ...state, 20 | [action.viewName]: [...currentHistory, action.path] 21 | }; 22 | case '@@FRAMEWORK7_GO_BACK': 23 | const editedHistory = [...state[action.viewName].slice(0, state[action.viewName].length - 1)]; 24 | 25 | return { 26 | ...state, 27 | [action.viewName]: editedHistory 28 | }; 29 | default: 30 | return state; 31 | } 32 | }; 33 | 34 | export const routingReducer = combineReducers({ 35 | history: historyReducer 36 | }); -------------------------------------------------------------------------------- /src/redux/actions/modal-actions.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ShowAlertAction, 3 | CloseAlertAction, 4 | ShowPreloaderAction, 5 | HidePreloaderAction, 6 | CancelConfirmAction, 7 | AcceptConfirmAction, 8 | ShowConfirmAction 9 | } from './framework7-actions'; 10 | 11 | export const showAlert = (text: string, title?: string): ShowAlertAction => { 12 | return { 13 | type: '@@FRAMEWORK7_SHOW_ALERT', 14 | text, 15 | title 16 | }; 17 | }; 18 | 19 | export const closeAlert = (): CloseAlertAction => { 20 | return { type: '@@FRAMEWORK7_CLOSE_ALERT' }; 21 | }; 22 | 23 | export const showConfirm = (text: string, title?: string): ShowConfirmAction => { 24 | return { 25 | type: '@@FRAMEWORK7_SHOW_CONFIRM', 26 | text, 27 | title 28 | } 29 | } 30 | 31 | export const cancelConfirm = (): CancelConfirmAction => { 32 | return { type: '@@FRAMEWORK7_CANCEL_CONFIRM' }; 33 | }; 34 | 35 | export const acceptConfirm = (): AcceptConfirmAction => { 36 | return { type: '@@FRAMEWORK7_ACCEPT_CONFIRM' }; 37 | } 38 | 39 | export const showPreloader = (loadingText?: string): ShowPreloaderAction => { 40 | return { 41 | type: '@@FRAMEWORK7_SHOW_PRELOADER', 42 | loadingText: loadingText 43 | }; 44 | }; 45 | 46 | export const hidePreloader = (): HidePreloaderAction => { 47 | return { type: '@@FRAMEWORK7_HIDE_PRELOADER' }; 48 | }; -------------------------------------------------------------------------------- /src/state-kernels/modals/modal-message-helper.ts: -------------------------------------------------------------------------------- 1 | import { IModalState, IModalMessageState } from "../../state/modals-state"; 2 | import { StateKernel } from "../../state-kernel"; 3 | 4 | export interface IModalMessageButton { 5 | text: string, onClick(): void 6 | } 7 | 8 | export class ModalMessageHelper { 9 | private modal: any; 10 | private framework7: any; 11 | protected buttons: IModalMessageButton[]; 12 | 13 | constructor(framework7: any, buttons: IModalMessageButton[]) { 14 | this.framework7 = framework7; 15 | this.buttons = buttons; 16 | } 17 | 18 | public handleStateChange(state: IModalMessageState) { 19 | if (state.text || state.title) { 20 | this.show(state.text, state.title); 21 | } else { 22 | this.close(); 23 | } 24 | } 25 | 26 | private show(text: string, title: string) { 27 | if (!this.modal) { 28 | this.modal = this.framework7.dialog.create({ 29 | text, 30 | title, 31 | buttons: this.buttons 32 | }) 33 | .open(); 34 | } else { 35 | this.close(); 36 | this.show(text, title); 37 | } 38 | } 39 | 40 | private close() { 41 | if (this.modal) { 42 | this.framework7.dialog.close(); 43 | this.modal = null; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/redux/actions/framework7-actions.ts: -------------------------------------------------------------------------------- 1 | //Modal actions 2 | export interface ShowAlertAction { 3 | type: '@@FRAMEWORK7_SHOW_ALERT'; 4 | title: string; 5 | text: string; 6 | }; 7 | 8 | export interface CloseAlertAction { 9 | type: '@@FRAMEWORK7_CLOSE_ALERT'; 10 | }; 11 | 12 | export interface ShowPreloaderAction { 13 | type: '@@FRAMEWORK7_SHOW_PRELOADER'; 14 | loadingText: string; 15 | }; 16 | 17 | export interface ShowConfirmAction { 18 | type: '@@FRAMEWORK7_SHOW_CONFIRM', 19 | title: string; 20 | text: string; 21 | } 22 | 23 | export interface CancelConfirmAction { 24 | type: '@@FRAMEWORK7_CANCEL_CONFIRM' 25 | } 26 | 27 | export interface AcceptConfirmAction { 28 | type: '@@FRAMEWORK7_ACCEPT_CONFIRM' 29 | } 30 | 31 | export interface HidePreloaderAction { 32 | type: '@@FRAMEWORK7_HIDE_PRELOADER'; 33 | }; 34 | 35 | export type ModalAction = 36 | ShowAlertAction 37 | | CloseAlertAction 38 | | ShowPreloaderAction 39 | | HidePreloaderAction 40 | | ShowConfirmAction 41 | | AcceptConfirmAction 42 | | CancelConfirmAction 43 | 44 | //Routing actions 45 | export interface NavigateToAction { 46 | type: '@@FRAMEWORK7_NAVIGATE_TO'; 47 | path: string; 48 | replace: boolean; 49 | viewName?: string; 50 | }; 51 | 52 | export interface GoBackAction { 53 | type: '@@FRAMEWORK7_GO_BACK'; 54 | viewName?: string; 55 | }; 56 | 57 | export type RoutingAction = NavigateToAction | GoBackAction; -------------------------------------------------------------------------------- /src/state-kernels/modals/preloader-kernel.ts: -------------------------------------------------------------------------------- 1 | import {StateKernel} from '../../state-kernel'; 2 | import {IPreloaderState, IModalState} from '../../state/modals-state'; 3 | 4 | export class PreloaderKernel extends StateKernel { 5 | private preloaderModal: any; 6 | 7 | protected getState(fullState: IModalState) { 8 | return fullState.preloader; 9 | } 10 | 11 | protected handleStateChange(state: IPreloaderState) { 12 | if (state.visible) { 13 | this.showPreloader(state.loadingText); 14 | } else { 15 | this.hidePreloader(); 16 | } 17 | } 18 | 19 | private showPreloader(title: string) { 20 | if (!this.preloaderModal) { 21 | this.preloaderModal = this.framework7.preloader.show(title); 22 | } else { 23 | this.hidePreloader(); 24 | this.showPreloader(title); 25 | } 26 | } 27 | 28 | private hidePreloader() { 29 | if (this.preloaderModal) { 30 | this.framework7.preloader.hide(); 31 | 32 | const tempPreloaderModal = this.preloaderModal; 33 | 34 | //Sometimes, a timing issue causes the preloader to not get cleaned up, so we're making sure it always does. 35 | setTimeout(() => { 36 | if (tempPreloaderModal) { 37 | tempPreloaderModal.remove(); 38 | } 39 | }, 100); 40 | 41 | this.preloaderModal = null; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/redux/reducers/modal-reducer.ts: -------------------------------------------------------------------------------- 1 | import {combineReducers, Reducer} from 'redux'; 2 | 3 | import { 4 | ModalAction 5 | } from '../actions/framework7-actions'; 6 | import {IModalState, IModalMessageState, IPreloaderState} from '../../state/modals-state'; 7 | 8 | const initialModalMessageState: IModalMessageState = { 9 | modalMessageType: null, 10 | title: null, 11 | text: null 12 | }; 13 | 14 | const initialPreloaderState: IPreloaderState = { 15 | loadingText: null, 16 | visible: false 17 | }; 18 | 19 | export const modalMessageReducer: Reducer = ( 20 | state: IModalMessageState = initialModalMessageState, 21 | action: ModalAction 22 | ) => { 23 | switch (action.type) { 24 | case '@@FRAMEWORK7_SHOW_CONFIRM': 25 | return { 26 | modalMessageType: 'confirm', 27 | title: action.title, 28 | text: action.text 29 | }; 30 | case '@@FRAMEWORK7_SHOW_ALERT': 31 | return { 32 | modalMessageType: 'alert', 33 | title: action.title, 34 | text: action.text 35 | }; 36 | case '@@FRAMEWORK7_CANCEL_CONFIRM': 37 | case '@@FRAMEWORK7_ACCEPT_CONFIRM': 38 | case '@@FRAMEWORK7_CLOSE_ALERT': 39 | return { 40 | modalMessageType: null, 41 | title: null, 42 | text: null 43 | }; 44 | default: 45 | return state; 46 | } 47 | }; 48 | 49 | export const preloaderReducer: Reducer = (state: IPreloaderState = initialPreloaderState, action: ModalAction) => { 50 | switch (action.type) { 51 | case '@@FRAMEWORK7_SHOW_PRELOADER': 52 | return { 53 | loadingText: action.loadingText, 54 | visible: true 55 | }; 56 | case '@@FRAMEWORK7_HIDE_PRELOADER': 57 | return { 58 | loadingText: null, 59 | visible: false 60 | }; 61 | default: 62 | return state; 63 | } 64 | }; 65 | 66 | export const modalsReducer = combineReducers({ 67 | modalMessage: modalMessageReducer, 68 | preloader: preloaderReducer 69 | }); -------------------------------------------------------------------------------- /src/state-kernel.ts: -------------------------------------------------------------------------------- 1 | export interface StateKernel { 2 | onFramework7Set?(framework7?: any): void; 3 | onRouterSet?(router?: any): void; 4 | } 5 | 6 | interface ActionListener { 7 | actionType: string; 8 | callback: (action: any) => void; 9 | single: boolean; 10 | } 11 | 12 | export abstract class StateKernel { 13 | private previousState: TState; 14 | private testMode: boolean; 15 | private actionDispatchHandler: (action: any) => void; 16 | private actionListeners: ActionListener[] = []; 17 | protected children: StateKernel[] = []; 18 | protected framework7: any; 19 | 20 | constructor(testMode: boolean = false) { 21 | this.testMode = testMode; 22 | } 23 | 24 | public setState(newFullState: any) { 25 | if (this.testMode) return; 26 | 27 | const myNewState = this.getState(newFullState); 28 | 29 | if (myNewState != this.previousState) { 30 | this.handleStateChange(myNewState); 31 | } 32 | 33 | this.previousState = myNewState; 34 | 35 | this.children.forEach(child => { 36 | child.setState(myNewState); 37 | }); 38 | } 39 | 40 | public setTestMode(testMode: boolean) { 41 | this.testMode = testMode; 42 | } 43 | 44 | public setFramework7(framework7: any) { 45 | this.framework7 = framework7; 46 | this.children.forEach(child => child.setFramework7(framework7)); 47 | if (this.onFramework7Set) this.onFramework7Set(framework7); 48 | } 49 | 50 | public setActionDispatchHandler(actionDispatchHandler: (action: any) => void) { 51 | this.actionDispatchHandler = actionDispatchHandler; 52 | this.children.forEach(child => child.setActionDispatchHandler(this.dispatchAction.bind(this))); 53 | } 54 | 55 | public listenForAction(actionType: string, callback: (action: any) => void, single: boolean = false) { 56 | this.actionListeners.push({ 57 | actionType, 58 | callback, 59 | single 60 | }); 61 | } 62 | 63 | public getActionPromise(actionType: string) { 64 | return new Promise(resolve => { 65 | this.listenForAction(actionType, resolve, true); 66 | }); 67 | } 68 | 69 | public dispatchAction(action: any) { 70 | this.actionDispatchHandler(action); 71 | 72 | this.actionListeners.forEach(listener => { 73 | if (listener.actionType === action.type) { 74 | listener.callback(action); 75 | } 76 | }); 77 | 78 | this.actionListeners = this.actionListeners.filter(listener => listener.actionType !== action.type || !listener.single); 79 | } 80 | 81 | protected abstract handleStateChange(newState: TState): void; 82 | protected abstract getState(state: any): TState; 83 | } -------------------------------------------------------------------------------- /src/state-kernels/routing-kernel.ts: -------------------------------------------------------------------------------- 1 | import {StateKernel} from '../state-kernel'; 2 | import {IRoutingState} from '../state/routing-state'; 3 | import {IFramework7State} from '../state/framework7-state'; 4 | import {navigateTo} from '../redux/actions/routing-actions'; 5 | import {HistoryReconciler} from './routing/history-reconciler'; 6 | 7 | export class RoutingKernel extends StateKernel { 8 | protected getState(fullState: IFramework7State) { 9 | return fullState.routing; 10 | } 11 | 12 | protected handleStateChange(state: IRoutingState) { 13 | Object.keys(state.history).forEach((viewName) => { 14 | this.reconcileHistories(viewName, state.history[viewName]); 15 | }); 16 | } 17 | 18 | onFramework7Set() { 19 | this.framework7.once('pageInit', () => this.initializeHistory()); 20 | } 21 | 22 | private initializeHistory() { 23 | const mainView = this.framework7.views.find((view: any) => view.main); 24 | 25 | if (!mainView) { 26 | throw new Error('Framework7 Redux requires a main view'); 27 | } 28 | 29 | this.framework7.views.forEach((view: any) => { 30 | const router = view.router; 31 | 32 | if (router.history.length) { 33 | router.history.forEach((f7HistoryUrl: string) => { 34 | this.dispatchAction(navigateTo(f7HistoryUrl, false, view.name || view.main && 'main')); 35 | }); 36 | } 37 | }); 38 | } 39 | 40 | private reconcileHistories(viewName: string, newHistory: string[]) { 41 | if (!this.framework7) return; 42 | 43 | const view = this.framework7.views.find((view: any) => { 44 | if (viewName === 'main') { 45 | return view.main; 46 | } else { 47 | return view.name === viewName; 48 | } 49 | }); 50 | 51 | if (!view) { 52 | // If view no longer exists, ignore it for now. The state for that view will get preserved in the store 53 | // and if that view gets recreated at some point, it will be restored to the correct state. For example, 54 | // if a page is using a routable panel that has a view with multiple pages, and that routable panel gets 55 | // destroyed after moving elsewhere, and then gets recreated after navigating back to the original page, 56 | // this will preserve the page in the panel where the user left off. 57 | return; 58 | } 59 | 60 | const reconciler = new HistoryReconciler(view.router, view.router.history, newHistory); 61 | 62 | reconciler 63 | .getOperationsToReconcileHistories() 64 | .forEach(operation => { 65 | if (operation.forward) { 66 | view.router.navigate(operation.url, { reloadCurrent: operation.replace }); 67 | } else { 68 | view.router.back(); 69 | } 70 | }); 71 | } 72 | } -------------------------------------------------------------------------------- /src/state-kernels/routing/history-reconciler.ts: -------------------------------------------------------------------------------- 1 | export interface IHistoryOperation { 2 | url: string; 3 | forward: boolean; 4 | replace: boolean; 5 | } 6 | 7 | export class HistoryReconciler { 8 | private router: any; 9 | private framework7History: string[]; 10 | private newHistory: string[]; 11 | private operations: IHistoryOperation[]; 12 | 13 | constructor(router: any, framework7History: string[], newHistory: string[]) { 14 | this.router = router; 15 | this.framework7History = [...framework7History]; 16 | this.newHistory = [...newHistory]; 17 | } 18 | 19 | public getOperationsToReconcileHistories() { 20 | this.operations = []; 21 | this.fastForwardToFirstNonMatchingPage(); 22 | this.rewindFramework7History(); 23 | 24 | if (this.currentF7HistoryUrl && this.currentNewHistoryUrl) { 25 | this.replaceLastFramework7UrlWithNewUrl(); 26 | } 27 | 28 | if (this.newHistory.length) { 29 | this.addRemainingNewUrlsToFramework7History(); 30 | } 31 | 32 | return this.operations; 33 | } 34 | 35 | private get currentF7HistoryUrl() { 36 | return this.framework7History[0]; 37 | } 38 | 39 | private get currentNewHistoryUrl() { 40 | return this.newHistory[0]; 41 | } 42 | 43 | private get currentF7HistoryPagePath() { 44 | return this.currentF7HistoryUrl && this.router.findMatchingRoute(this.currentF7HistoryUrl).url; 45 | } 46 | 47 | private get currentNewHistoryPagePath() { 48 | return this.currentNewHistoryUrl && this.router.findMatchingRoute(this.currentNewHistoryUrl).url; 49 | } 50 | 51 | private fastForwardToFirstNonMatchingPage() { 52 | while (this.currentF7HistoryUrl && this.currentNewHistoryUrl && this.currentF7HistoryPagePath === this.currentNewHistoryPagePath) { 53 | if (this.currentF7HistoryUrl !== this.currentNewHistoryUrl) { 54 | this.operations.push({ 55 | forward: true, 56 | url: this.currentNewHistoryUrl, 57 | replace: false 58 | }); 59 | } 60 | 61 | const lastNewHistoryUrl = this.newHistory.shift(); 62 | this.framework7History.shift(); 63 | 64 | if (this.currentF7HistoryUrl && !this.currentNewHistoryUrl) { 65 | this.operations.push({ 66 | url: lastNewHistoryUrl, 67 | forward: false, 68 | replace: false 69 | }); 70 | } 71 | } 72 | } 73 | 74 | private rewindFramework7History() { 75 | while (this.framework7History.length > 1) { 76 | this.operations.push({ 77 | forward: false, 78 | replace: false, 79 | url: this.framework7History.pop() 80 | }); 81 | } 82 | } 83 | 84 | private replaceLastFramework7UrlWithNewUrl() { 85 | this.operations.push({ 86 | forward: true, 87 | url: this.currentNewHistoryUrl, 88 | replace: true 89 | }); 90 | 91 | this.newHistory.shift(); 92 | this.framework7History.shift(); 93 | } 94 | 95 | private addRemainingNewUrlsToFramework7History() { 96 | while (this.newHistory.length) { 97 | this.operations.push({ 98 | forward: true, 99 | url: this.newHistory.pop(), 100 | replace: false 101 | }); 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Framework7 Redux 2 | ### Framework7 plug-in to keep your Redux store in sync with Framework7 3 | 4 | [Framework7](https://github.com/nolimits4web/Framework7) has functionality like routing and showing + hiding modals. This means that there is state in Framework7 for things like the current URL, whether or not a modal is showing, etc. This state is therefore not available in your store, which means that things like time travel debugging and server rendering with server state sent to the client state won't work. 5 | 6 | Framework7 Redux is a Framework7 plug-in that syncs state in Framework7 with your store. It also provides actions that you can call to do things like navigate to a URL, go back, and show + hide an alert. 7 | 8 | ### Who should use Framework7 Redux? 9 | 10 | If you aren't already familiar with [Redux](https://github.com/reactjs/redux) and using React with [Framework7](http://framework7.io), then you will probably want to go learn those libraries before using Framework7 Redux. 11 | 12 | Note that **this library is not mandatory** for using Redux with Framework7 and React. When you use Redux with Framework7 and React, you're using state from your store to control what prop values get passed into your components and re-rendering your components when the state changes. This works just fine without this library. 13 | 14 | If you want to control things like navigation and alert dialogs from Redux actions and want these things to work when you do server rendering or time-travel debugging, that's when you need to use Framework7 Redux. If you just want your components to be controlled by state and are fine with navigation and modals being handled outside of Redux, then you don't need Framework7 Redux. 15 | 16 | ### Getting started 17 | 18 | #### Starter template 19 | 20 | The simplest way to get started is to use the [Framework7 + React + Redux starter template](https://github.com/bencompton/framework7-redux-app-template). 21 | 22 | #### Custom setup 23 | 24 | Pull down Framework7 Redux from NPM like so: 25 | 26 | ``` 27 | npm install --save framework7-redux 28 | ``` 29 | 30 | Next, update your store code to look like this: 31 | 32 | ```javascript 33 | import { Framework7StateKernel, framework7Reducer, syncFramework7WithStore } from 'framework7-redux'; 34 | 35 | export const framework7StateKernel = new Framework7StateKernel(); 36 | 37 | export const store = createStore( 38 | combineReducers({ 39 | framework7: framework7Reducer, 40 | ... 41 | ... 42 | }) 43 | ); 44 | 45 | syncFramework7WithStore(store, framework7StateKernel); 46 | ``` 47 | 48 | Finally, configure your root Framework7 app React component: 49 | 50 | ```javascript 51 | import Framework7 from 'framework7/framework7.esm.bundle'; 52 | import Framework7React, { App, Views } from 'framework7-react'; 53 | 54 | import { routes } from './routes'; 55 | import { store, framework7StateKernel } from './store'; 56 | import { framework7ReduxPlugin } from 'framework7-redux'; 57 | 58 | const params = { 59 | ... 60 | routes, 61 | stateKernel: framework7StateKernel, 62 | clicks: { 63 | externalLinks: 'a[href="#"]' // Bypass the built-in routing for link clicks 64 | }, 65 | panel: { 66 | closeByBackdropClick: false // Bypass the built-in routing when clicking panel backdrops 67 | }, 68 | popup: { 69 | closeByBackdropClick: false // Bypass the built-in routing when clicking popup backdrops 70 | } 71 | }; 72 | 73 | Framework7.use(Framework7React); 74 | Framework7.use(framework7ReduxPlugin); 75 | 76 | const MyApp = () => { 77 | return ( 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | ); 86 | }; 87 | ``` 88 | 89 | ### Navigation 90 | 91 | By default, the router in Framework7 will automatically navigate to different pages when the user clicks an anchor tag with an href attribute. This works well for simpler apps, but for larger and more complex apps, it is recommended to handle all navigation through actions and only have presentation logic in your React components. In order to accomplish this, some default navigation settings in Framework7 must be disabled first. 92 | 93 | #### Links 94 | 95 | In the Setup section above, the Framework7 param `clicks -> externalLinks` is set to `a[href="#"]` to disable the default automatic Framework7 Link routing behavior. Once that is disabled, you can then safely call actions from the Link's `onClick` event and control all routing through Redux actions. 96 | 97 | #### Tabs 98 | 99 | Tabs in Framework7 can be controlled via routes, as described in the [routing docs](http://framework7.io/docs/routes.html). Once tabs are configured to be routable, the tab links should have `onClick` handlers that call actions just like any other link used with Framework7 Redux. 100 | 101 | #### Popups / Panels 102 | 103 | Popups and panels can be controlled via routes as of Framework7 v3, as described in the [routing docs](http://framework7.io/docs/routes.html). The behavior of closing Panels and Popups on backdrop click should also be disabled in the Framework7 parameters as shown in the Setup section above. Once that is accomplished, you can use actions to navigate forward to a Popup or Panel route to open them, and then use actions to navigate back to close the Popup or Panel. 104 | 105 | #### Navigating forward and back with actions 106 | 107 | Once your the default Framework7 navigation behaviors are disabled and your components are configured to be routable, the following code can be used in your actions to control navigation: 108 | 109 | ```javascript 110 | import { navigateTo, goBack } from 'framework7-redux' 111 | 112 | var routes = [{ 113 | path: '/', 114 | component: HomePage 115 | }, { 116 | path: '/page-1/', 117 | component: Page1 118 | }]; 119 | 120 | ... 121 | ... 122 | 123 | //Go to page 1 124 | store.dispatch(navigateTo('/page-1/')); 125 | 126 | //Go to page 2 and replace page 1 in the history 127 | store.dispatch(navigateTo('/page-1/', true)); 128 | 129 | //Go back to the home page 130 | store.dispatch(goBack()); 131 | 132 | //Navigate a view other than main view 133 | store.dispatch(nagivateTo('/left-panel/about/', true, 'left-panel-view')); 134 | store.dispatch(goBack('left-panel-view'); 135 | ``` 136 | 137 | ### Modals 138 | 139 | Framework7's API can be called for alerts, confirm dialogs, etc. While this approach is fine for simpler apps, it is better to control modals via actions so their state will be in your store. 140 | 141 | ```javascript 142 | import { showAlert, closeAlert, showPreloader, hidePreloader } from 'framework7-redux' 143 | 144 | //Show an alert with no title and the specified alert text 145 | store.dispatch(showAlert(('Alert text!')); 146 | 147 | //Close the alert 148 | store.dispatch(closeAlert()); 149 | 150 | //Show an alert with the specified text and title 151 | store.dispatch(showAlert(('Alert text!', 'Alert title')); 152 | 153 | //Show the global app loading spinner 154 | store.dispatch(showPreloader()); 155 | 156 | //Hide the global app loading spinner 157 | store.dispatch(hidePreloader()); 158 | 159 | //Show the global app loading spinner with custom loading text 160 | store.dispatch(showPreloader('Saving...')); 161 | 162 | //Show a confirm dialog 163 | store.dispatch(showConfirm('Are you sure you want to do this?', 'Are you sure?')); 164 | 165 | //Cancel a confirm dialog 166 | store.dispatch(cancelConfirm()); 167 | 168 | //Accept a confirm dialog 169 | store.dispatch(acceptConfirm()); 170 | ``` 171 | 172 | It is also possible to get a promise that resolves when the user closes an alert: 173 | 174 | ```javascript 175 | import {showAlert, closeAlert} from 'framework7-redux' 176 | import {framework7StateKernel} from './store'; 177 | 178 | store.dispatch(showAlert('Alert text')); 179 | 180 | framework7StateKernel.getActionPromise(closeAlert().type) 181 | .then(() => store.dispatch(showAlert('Alert closed!'))); 182 | ``` 183 | 184 | You can then use the promise in the appropriate manner for whatever async action middleware you are using. For example, here is how it would look in [redux-thunk](https://github.com/gaearon/redux-thunk): 185 | 186 | ```javascript 187 | const productFetchFailed = () => { 188 | return dispatch => { 189 | dispatch(showAlert('Product fetch failed!')); 190 | 191 | //Retry product fetch after the user clicks the "Ok" button on the alert 192 | framework7StateKernel.getActionPromise(closeAlert().type) 193 | .then(() => dispatch(fetchProducts())) 194 | }; 195 | }; 196 | ``` 197 | 198 | Here is an example of a confirm dialog with redux-thunk: 199 | 200 | ```javascript 201 | const someRiskyAction = () => { 202 | return dispatch => { 203 | dispatch(showConfirm('Are you sure you want to do this?', 'Are you sure?')); 204 | 205 | Promise.race([ 206 | framework7StateKernel.getActionPromise(acceptConfirm().type).then(() => true), 207 | framework7StateKernel.getActionPromise(cancelConfirm().type).then(() => false) 208 | ]) 209 | .then(confirmed => { 210 | if (confirmed) { 211 | dispatch(completeRiskyAction()); 212 | } 213 | }); 214 | }; 215 | }; 216 | ``` 217 | 218 | ### Selectors 219 | 220 | Framework7 Redux provides some selectors to retrieve info from your state: 221 | 222 | ```javascript 223 | import { getCurrentRoute, getPreviousRoute } from 'framework7-redux'; 224 | 225 | // Returns the current URL in the history or undefined if none 226 | const currentUrl = getCurrentRoute(store.getState()); 227 | 228 | // Returns the previous URL in the history or undefined if none 229 | const previousUrl = getPreviousRoute(store.getState()); 230 | ``` 231 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------