This file contains hidden or 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 { createStore } from 'redux' | |
| import { persistStore, persistReducer } from 'redux-persist' | |
| import storage from 'redux-persist/lib/storage' | |
| import rootReducer from '../reducers' | |
| const persistConfig = { | |
| key: 'root', | |
| storage, | |
| } |
This file contains hidden or 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 { createStore } from 'redux' | |
| import rootReducer from '../reducers' | |
| import { loadState, saveState } from '../lib/localStorage' | |
| const persistStore = loadState() | |
| const store = createStore(rootReducer, persistStore) | |
| store.subscribe(() => { | |
| saveState(store.getState()) | |
| }) |
This file contains hidden or 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
| const loadState = () => { | |
| try { | |
| const serializedState = localStorage.getItem('store') | |
| if (serializedState === null) { | |
| return undefined | |
| } else { | |
| return JSON.parse(serializedState) | |
| } | |
| } catch (error) { | |
| return undefined |
This file contains hidden or 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 { expect } from 'chai' | |
| import supertest from 'supertest' | |
| import server from '../../src/server' | |
| describe('Test query', () => { | |
| it('has correct getCharacters query', (done) => { | |
| const request = supertest.agent(server) | |
| const query = { | |
| query: ` | |
| query { |
This file contains hidden or 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 { expect } from 'chai' | |
| import rootSchema from '../../src/schemas/rootSchema' | |
| describe('Test resolvers', () => { | |
| it('has correct getCharacters query', (done) => { | |
| const charactersQuery = rootSchema.getTypeMap().Query.getFields().getCharacters | |
| const expected = [ | |
| { id: '1', name: 'John Snow', gender: { name: 'Male' }} | |
| ] |
This file contains hidden or 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 { GraphQLString, GraphQLNonNull } from 'graphql' | |
| import { expect } from 'chai' | |
| import rootSchema from '../../src/schemas/rootSchema' | |
| describe('Test schema', () => { | |
| it('has correct character schema', () => { | |
| const characterSchema = rootSchema.getTypeMap().Character.getFields() | |
| expect(characterSchema).to.have.property('name') | |
| expect(characterSchema.name.type).to.deep.equals(GraphQLString) |
This file contains hidden or 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
| self.addEventListener('activate', event => { | |
| const cacheWhitelist = [CACHE_KEY] | |
| event.waitUntil( | |
| caches.keys().then(keyList => { | |
| return Promise.all(keyList.map(function(key) { | |
| if (cacheWhitelist.indexOf(key) === -1) { | |
| return caches.delete(key) | |
| } | |
| })) |
This file contains hidden or 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
| self.addEventListener('fetch', event => { | |
| event.respondWith( | |
| caches.match(event.request).then(cacheResp => { | |
| return cacheResp || fetch(event.request).then(response => { | |
| return caches.open(CACHE_KEY).then(cache => { | |
| cache.put(event.request, response.clone()) | |
| return response | |
| }) | |
| }) | |
| }) |
This file contains hidden or 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
| const VERSION = '1' | |
| const CACHE_KEY = `cache-v${VERSION}` | |
| const assetsToCache = [ | |
| '/', | |
| '/assets/css/app.css', | |
| '/assets/js/app.js', | |
| '/assets/images/icons/icon-16x16.png', | |
| '/assets/images/icons/icon-24x24.png', | |
| '/assets/images/icons/icon-36x36.png', | |
| '/assets/images/icons/icon-64x64.png', |
This file contains hidden or 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
| if ('serviceWorker' in navigator) { | |
| window.addEventListener('load', () => { | |
| navigator.serviceWorker.register("/service-worker.js").then(register => { | |
| console.log('Register succeeded in scope : ', register.scope) | |
| }) | |
| }) | |
| } |