From 680d6c9b3b58078b215723e745afaa351a92d429 Mon Sep 17 00:00:00 2001 From: onurtemizkan Date: Mon, 26 Sep 2016 02:02:50 +0300 Subject: [PATCH] Reformat [About/Newtab/Newtab/Wallpapers.js] to StandardJS Style (#1242) --- package.json | 1 - src/About/Newtab/Newtab/Wallpapers.js | 179 ++++++++++++-------------- 2 files changed, 84 insertions(+), 96 deletions(-) diff --git a/package.json b/package.json index 0202088cc..e9338c88f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/About/Newtab/Newtab/Wallpapers.js b/src/About/Newtab/Newtab/Wallpapers.js index 6a1f3c796..ef1c217b9 100644 --- a/src/About/Newtab/Newtab/Wallpapers.js +++ b/src/About/Newtab/Newtab/Wallpapers.js @@ -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 - , entries: {[key:ID]: Wallpaper.Model} +export type Model = { + active: ID, + order: Array, + 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] => - [ 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] => [ + 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.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.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):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))) ) - ] - ); + )) + ])