Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
fix(runtime): merges initial configuration with runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Nov 30, 2018
1 parent 2148b46 commit f7d689f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 63 deletions.
4 changes: 4 additions & 0 deletions docs/.vuepress/public/fixtures/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@
"image": ""
}
],
"runtime": {
"locale": "de-De",
"language": "de"
},
"visibleComponents": [
"tabInfo",
"tabChapters",
Expand Down
7 changes: 0 additions & 7 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import runtime from 'utils/runtime'
import { createApp } from 'core'

// Store
Expand All @@ -9,12 +8,6 @@ import actions from 'store/actions'
import App from './components/App'

export default config => {
// Enhance config with app debug information
config = {
runtime,
...config
}

// Initialize meta for store
store.dispatch(actions.init(config))

Expand Down
2 changes: 2 additions & 0 deletions src/effects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import chapterEffects from './chapters'
import volumeEffects from './volume'
import playbackEffects from './playback'
import transcriptEffects from './transcripts'
import runtimeEffects from './runtime'

import mediaPlayer from '../media'

Expand All @@ -32,6 +33,7 @@ const condEffects = [
conditionalEffect(quantileEffects),
conditionalEffect(volumeEffects),
conditionalEffect(componentsEffects),
conditionalEffect(runtimeEffects),
compose(conditionalEffect(chapterEffects)),
compose(conditionalEffect(transcriptEffects), hasProperty('transcripts'))
]
Expand Down
18 changes: 18 additions & 0 deletions src/effects/runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { get } from 'lodash'

import { INIT } from 'store/types'
import actions from 'store/actions'
import runtime from 'utils/runtime'

import { handleActions } from 'utils/effects'

export default handleActions({
[INIT]: ({ dispatch }, { payload }) => {
const config = get(payload, 'runtime', {})

dispatch(actions.setRuntime({
...runtime,
...config
}))
}
})
3 changes: 2 additions & 1 deletion src/store/runtime/actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createAction } from 'redux-actions'

import { SET_LANGUAGE } from '../types'
import { SET_LANGUAGE, SET_RUNTIME } from '../types'

export const setLanguage = createAction(SET_LANGUAGE)
export const setRuntime = createAction(SET_RUNTIME)
9 changes: 8 additions & 1 deletion src/store/runtime/actions.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import test from 'ava'
import { setLanguage } from './actions'
import { setLanguage, setRuntime } from './actions'

test(`setLanguage: creates the SET_LANGUAGE action`, t => {
t.deepEqual(setLanguage('de'), {
type: 'SET_LANGUAGE',
payload: 'de'
})
})

test(`setLanguage: creates the SET_LANGUAGE action`, t => {
t.deepEqual(setRuntime({ language: 'de' }), {
type: 'SET_RUNTIME',
payload: { language: 'de' }
})
})
6 changes: 3 additions & 3 deletions src/store/runtime/reducer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { handleActions } from 'redux-actions'

import { INIT, SET_LANGUAGE } from '../types'
import { SET_RUNTIME, SET_LANGUAGE } from '../types'

export const INITIAL_STATE = {}

export const reducer = handleActions({
[INIT]: (state, { payload }) => ({
[SET_RUNTIME]: (state, { payload }) => ({
...state,
...payload.runtime
...payload
}),
[SET_LANGUAGE]: (state, { payload }) => ({
...state,
Expand Down
55 changes: 4 additions & 51 deletions src/store/runtime/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,10 @@ let testAction

test.beforeEach(t => {
testAction = {
type: 'INIT',
type: 'SET_RUNTIME',
payload: {
title: 'title',
subtitle: 'subtitle',
publicationDate: '2016-02-11T03:13:55+00:00',
poster: '//episode/poster',
show: {
title: 'showTitle',
subtitle: 'Menschen! Technik! Sensationen!',
summary: 'Die muntere Talk Show um Leben mit Technik, das Netz und Technikkultur. Bisweilen Apple-lastig aber selten einseitig. Wir leben und lieben Technologie und reden darüber. Mit Tim, hukl, roddi, Clemens und Denis. Freak Show hieß irgendwann mal mobileMacs.',
poster: '//show/poster',
url: 'https://freakshow.fm'
},
duration: '04:15:32',
chapters: [
{ start: '00:00:00', title: 'Intro' },
{ start: '00:01:39', title: 'Begrüßung' },
{ start: '00:04:58', title: 'IETF Meeting Netzwerk' },
{ start: '00:18:37', title: 'Kalender' },
{ start: '00:33:40', title: 'Freak Show Bingo' },
{ start: '00:35:37', title: 'Wikipedia' },
{ start: '01:17:26', title: 'iPhone Akkukalibration' },
{ start: '01:24:55', title: 'Alte iPads und iPod touches' },
{ start: '01:31:02', title: 'Find My Friends' },
{ start: '01:41:46', title: 'iPhone Music Player' },
{ start: '01:56:13', title: 'Apple Watch' },
{ start: '02:11:51', title: 'Kommandozeile: System Appreciation' },
{ start: '02:23:10', title: 'Sound und Design für Games' },
{ start: '02:24:59', title: 'Kommandozeile: Remote Deployment' },
{ start: '02:32:37', title: 'Kommandozeile: Man Pages' },
{ start: '02:44:31', title: 'Kommandozeile: screen vs. tmux' },
{ start: '02:58:02', title: 'Star Wars: Machete Order & Phantom Edit' },
{ start: '03:20:05', title: 'Kopfhörer-Ersatzteile' },
{ start: '03:23:39', title: 'Dante' },
{ start: '03:38:03', title: 'Dante Via' },
{ start: '03:45:33', title: 'Internet of Things Security' },
{ start: '03:56:11', title: 'That One Privacy Guy\'s VPN Comparison Chart' },
{ start: '04:10:00', title: 'Ausklang' }
],
audio: [
'my/audio/url.mp4'
],
reference: {
config: '//config/reference',
share: '//share/reference',
origin: '//origin/reference'
},
runtime: {
language: 'en',
platform: 'desktop'
}
language: 'en',
platform: 'desktop'
}
}
})
Expand All @@ -64,7 +17,7 @@ test(`runtime: it is a reducer function`, t => {
t.is(typeof runtime, 'function')
})

test(`runtime: it extracts the runtime on INIT`, t => {
test(`runtime: it extracts the runtime on SET_RUNTIME`, t => {
const result = runtime('', testAction)
t.deepEqual(result, {
language: 'en',
Expand Down
1 change: 1 addition & 0 deletions src/store/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const LOAD_QUANTILES = 'LOAD_QUANTILES'
export const SET_QUANTILE = 'SET_QUANTILE'

// Runtime
export const SET_RUNTIME = 'SET_RUNTIME'
export const SET_LANGUAGE = 'SET_LANGUAGE'

// Share
Expand Down

0 comments on commit f7d689f

Please sign in to comment.