Skip to content

Commit 0873008

Browse files
committed
add todo-cards-app | Feed. You. Stuff. No time. (C) whatthecommit.com
1 parent c7a358c commit 0873008

23 files changed

+8129
-32
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ script:
3030

3131
- >
3232
for path in \
33+
functional-js/todo-cards-app \
3334
functional-js/tips-calculator-app \
3435
functional-js/functional-starter-app \
3536
functional-js/functional-temperature-converter-app \

bin/clean.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
# functional-js
33
for path in \
4+
todo-cards-app \
45
tips-calculator-app \
56
functional-starter-app \
67
functional-temperature-converter-app \

functional-js/functional-starter-app/src/app/Components.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ import { } from './Actions';
77
const { div, h1, pre, } = hh(h);
88

99
export function view(dispatch, state) {
10-
return contentWrapper([
11-
applicationHeader(),
12-
debugAppState(state),
13-
]);
14-
}
15-
16-
function applicationHeader() {
17-
return h1({ className: 'f1 pv2 bb' }, 'App');
18-
}
19-
20-
function contentWrapper(elements) {
2110
return div({ className: 'mw6 center' }, [
22-
...elements,
11+
h1({ className: 'f1 pv2 bb' }, 'App'),
12+
debugAppState(state),
2313
]);
2414
}
2515

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mapOf } from './Actions';
22

33
export const initialState = mapOf({
4-
enableLocalStorage: true,
4+
enableLocalStorage: false,
55
});

functional-js/functional-starter-app/src/app/LocalStorage.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import { initialState } from './InitialState';
22
import { version, name } from '../../package.json';
33
import { storeLocalStorageStateAction } from './Actions';
44

5-
/** state management */
5+
/** impure: state management by using browser local storage for backup / restore last user session */
66

77
const _key = `com.github.daggerok:${name}:${version}`;
88

9-
function restoreState(json) {
9+
export function restoreState() {
10+
if (!initialState.enableLocalStorage) {
11+
return initialState;
12+
}
13+
const json = localStorage.getItem(_key);
1014
if (!json || '{}' === json) {
11-
return JSON.stringify(initialState);
15+
return initialState;
1216
}
13-
return json;
17+
return JSON.parse(json);
1418
}
1519

16-
export const deserialize = () => !initialState.enableLocalStorage ? {} :
17-
JSON.parse(restoreState(localStorage.getItem(_key)));
18-
19-
export const serialize = state => !initialState.enableLocalStorage ? {} :
20+
export const backupState = state => !initialState.enableLocalStorage ? {} :
2021
localStorage.setItem(_key, JSON.stringify(state));
2122

2223
export const registerLocalStorageOnUnloadDispatcher = dispatch => !initialState.enableLocalStorage ? {} :
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { serialize } from './LocalStorage';
1+
import { backupState } from './LocalStorage';
22
import { mapOf, types } from './Actions';
33
import * as R from 'ramda';
44

@@ -10,14 +10,12 @@ export function reducer(action, state) {
1010
switch (type) {
1111

1212
case types.STORE_STATE: {
13-
serialize(state);
14-
return mapOf({ ...state });
13+
backupState(state);
14+
return state;
1515
}
1616

1717
default: {
18-
return mapOf({ ...state });
18+
return state;
1919
}
2020
}
21-
22-
return state;
2321
}

functional-js/functional-starter-app/src/app/VirtualDOM.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { reducer } from './Reducer';
55
import { view } from './Components';
66
import { registerLocalStorageOnUnloadDispatcher } from './LocalStorage';
77

8-
/** impure */
8+
/** impure: perform efficient virtual DOM tree update (re-render) */
99

1010
export function render(initialState, rootNode) {
1111
let state = initialState;
@@ -16,8 +16,8 @@ export function render(initialState, rootNode) {
1616

1717
registerLocalStorageOnUnloadDispatcher(dispatch);
1818

19-
function dispatch(type) {
20-
const newState = reducer(type, state);
19+
function dispatch(action) {
20+
const newState = reducer(action, state);
2121
const newView = view(dispatch, newState);
2222
const patches = diff(currentView, newView);
2323

functional-js/functional-starter-app/src/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render } from './app/VirtualDOM';
2-
import { deserialize } from './app/LocalStorage';
2+
import { restoreState } from './app/LocalStorage';
33

4-
const initialState = deserialize();
4+
const initialState = restoreState();
55

66
render(
77
initialState,

functional-js/todo-cards-app/.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"browsers": ["last 2 versions", "safari >= 7", "chrome >= 36", "firefox >= 28"]
6+
}
7+
}],
8+
"stage-0"
9+
]
10+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.idea/
2+
*.iml
3+
*.ipr
4+
*.iws
5+
6+
.cache/
7+
dist/
8+
9+
node_modules/
10+
.DS_Store
11+
*.log*
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
= functional-starter-app image:https://travis-ci.org/daggerok/js-examples.svg?branch=master["Build Status", link="https://travis-ci.org/daggerok/js-examples"]
2+
3+
TODO:
4+
5+
- create card
6+
- refactoring to make cancel changes ork with reverting to prev state
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# add base tag:
4+
# <head> -> <head><base href="/js-examples/"/>
5+
6+
if ! [ -z "$1" ]; then
7+
if [ -f "$1" ]; then
8+
sed -i -e "s/\(<head>\)/<head><base href=\"\/js-examples\/\"\/>/g" $1
9+
rm -rf "$1-e"
10+
fi
11+
fi

0 commit comments

Comments
 (0)