Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Reformat [About/Newtab/Newtab/Wallpapers.js] to StandardJS Style (#1242) #1253

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"src/About/Newtab/Newtab/Tile.js",
"src/About/Newtab/Newtab/Tiles.js",
"src/About/Newtab/Newtab/Wallpaper.js",
"src/About/Newtab/Newtab/Wallpapers.js",
"src/About/Repl/Main.js",
"src/About/Repl/Repl.js",
"src/About/Repl/Repl/Cell.js",
Expand Down
179 changes: 84 additions & 95 deletions src/About/Newtab/Newtab/Wallpapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,122 +4,111 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import {Effects, html, thunk, forward} from "reflex"
import {merge, tagged} from "../../../Common/Prelude"
import {Style, StyleSheet} from "../../../Common/Style";
import * as Unknown from "../../../Common/Unknown";
import {Effects, html, thunk, forward} from 'reflex'
import {merge} from '../../../Common/Prelude'
import {StyleSheet} from '../../../Common/Style'
import * as Unknown from '../../../Common/Unknown'

import hardcodedWallpaper from "../Wallpaper.json";
import * as Wallpaper from "./Wallpaper";
import hardcodedWallpaper from '../Wallpaper.json'
import * as Wallpaper from './Wallpaper'


import type {Address, DOM} from "reflex"
import type {Address, DOM} from 'reflex'

export type URI = Wallpaper.URI
export type Color = Wallpaper.Color
export type ID = string

export type Model =
{ active: ID
, order: Array<ID>
, entries: {[key:ID]: Wallpaper.Model}
export type Model = {
active: ID,
order: Array<ID>,
entries: {
[key:ID]: Wallpaper.Model
}
}

export type Action =
| { type: "ChooseWallpaper"
, id: ID
| {
type: 'ChooseWallpaper',
id: ID
}
| { type: "Wallpaper"
, id: ID
, action: Wallpaper.Action
| {
type: 'Wallpaper',
id: ID,
action: Wallpaper.Action
}


export const init =
():[Model, Effects<Action>] =>
[ hardcodedWallpaper
, Effects.none
];


const ByID =
id =>
action =>
WallpaperAction(id, action);

const WallpaperAction =
(id, action) =>
( action.type === 'Choose'
? Choose(id)
: { type: "Wallpaper"
, id
, action
}
)

const Choose =
id =>
( { type: "ChooseWallpaper"
, id
}
)
():[Model, Effects<Action>] => [
hardcodedWallpaper,
Effects.none
]

const ByID = id =>
action => WallpaperAction(id, action)

const WallpaperAction = (id, action) => (
action.type === 'Choose' ? Choose(id) : {
type: 'Wallpaper',
id,
action
}
)

const Choose = id => ({
type: 'ChooseWallpaper',
id
})

const notFound =
{ src: null
, color: '#fff'
, isDark: false
}
const notFound = {
src: null,
color: '#fff',
isDark: false
}

export const active =
({entries, active}:Model):Wallpaper.Model =>
( entries[active] || notFound )
({entries, active}:Model):Wallpaper.Model => (
entries[active] || notFound
)

export const update =
(model:Model, action:Action):[Model, Effects<Action>] =>
( action.type === 'ChooseWallpaper'
? [ merge(model, {active: action.id})
, Effects.none
]
: Unknown.update(model, action)
);

const styleSheet = StyleSheet.create
( { base:
{ display: 'block'
, color: '#999'
, fontSize: '12px'
, lineHeight: '20px'
, position: 'absolute'
, bottom: '10px'
, left: 0
, textAlign: 'center'
, width: '100%'
}
, inner:
{}
}
);
(model:Model, action:Action):[Model, Effects<Action>] => (
action.type === 'ChooseWallpaper' ? [
merge(model, {active: action.id}),
Effects.none
] : Unknown.update(model, action)
)

const styleSheet = StyleSheet.create({
base: {
display: 'block',
color: '#999',
fontSize: '12px',
lineHeight: '20px',
position: 'absolute',
bottom: '10px',
left: 0,
textAlign: 'center',
width: '100%'
},
inner: {}
})

export const view =
(model:Model, address:Address<Action>):DOM =>
html.div
( { className: 'wallpaper'
, style: styleSheet.base
}
, [ html.div
( { className: 'wallpaper-inner'
, style: styleSheet.inner
}
, model.order.map
( id =>
thunk
( String(id)
, Wallpaper.view
, model.entries[id]
, forward(address, ByID(String(id)))
)
)
html.div({
className: 'wallpaper',
style: styleSheet.base
}, [
html.div({
className: 'wallpaper-inner',
style: styleSheet.inner
},
model.order.map(id =>
thunk(
String(id),
Wallpaper.view,
model.entries[id],
forward(address, ByID(String(id)))
)
]
);
))
])