-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gaperton/develop
Develop
- Loading branch information
Showing
11 changed files
with
240 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import document from "document"; | ||
import { Application } from './view' | ||
import { Screen1 } from './screen1' | ||
import { Screen2 } from './screen2' | ||
|
||
class MultiScreenApp extends Application { | ||
screen1 = new Screen1(); | ||
screen2 = new Screen2(); | ||
|
||
// Called once on application's start... | ||
onMount(){ | ||
// Set initial screen. | ||
// Same as Application.switchTo( 'screen1' ), which might be used to switch screen from anywhere. | ||
this.screen = this.screen2; | ||
|
||
document.onkeypress = this.onKeyPress; | ||
} | ||
|
||
// Event handler, must be pinned down to the class to preserve `this`. | ||
onKeyPress = ({ key }) => { | ||
if( key === 'down' ){ | ||
// Just switch between two screens we have. | ||
Application.switchTo( this.screen === this.screen1 ? 'screen2' : 'screen1' ); | ||
} | ||
} | ||
} | ||
|
||
// Create and start the application. | ||
MultiScreenApp.start(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { View, $at } from './view' | ||
import clock from 'clock' | ||
|
||
const $ = $at( '#screen-1' ); | ||
|
||
export class Screen1 extends View { | ||
// Root view element used to show/hide the view. | ||
el = $(); // Just the #screen-1 element. | ||
|
||
// Element group. | ||
time = new Time(); | ||
|
||
// The view state. | ||
seconds = 0; | ||
|
||
onMount(){ | ||
// Subscribe for the clock... | ||
clock.granularity = 'seconds'; | ||
clock.ontick = this.onTick; | ||
} | ||
|
||
onTick = () => { | ||
// Update the state and force render. | ||
this.seconds++; | ||
this.render(); | ||
} | ||
|
||
onRender(){ | ||
// Render the elements group. | ||
this.time.render( this.seconds ); | ||
} | ||
|
||
onUnmount(){ | ||
// Unsubscribe from the clock | ||
clock.granularity = 'off'; | ||
clock.ontick = null; | ||
} | ||
} | ||
|
||
// Elements group. Used to group the DOM elements and their update logic together. | ||
class Time { | ||
// Elements... | ||
minutes = $( '#minutes' ); | ||
seconds = $( '#seconds' ); | ||
|
||
// UI update method(s). Can have any name, it's just the pattern. | ||
// Element groups have no lifecycle hooks, thus all the data required for UI update | ||
// must be passed as arguments. | ||
render( seconds ){ | ||
this.minutes.text = ( seconds / 60 ) | 0; | ||
this.seconds.text = seconds % 60; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { View, $at } from './view' | ||
|
||
// Create the root selector for the view... | ||
const $ = $at( '#screen-2' ); | ||
|
||
export class Screen2 extends View { | ||
// Specify the root view element. | ||
// When set, it will be used to show/hide the view on mount and unmount. | ||
el = $(); | ||
|
||
// Lifecycle hook executed on `view.mount()`. | ||
onMount(){ | ||
// TODO: insert subviews... | ||
// TODO: subscribe for events... | ||
} | ||
|
||
// Lifecycle hook executed on `view.unmount()`. | ||
onUnmount(){ | ||
// TODO: unsubscribe from events... | ||
} | ||
|
||
// Custom UI update logic, executed on `view.render()`. | ||
onRender(){ | ||
// TODO: put DOM manipulations here... | ||
// Call this.render() to update UI. | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"fitbit": { | ||
"appUUID": "d84e4e76-0ded-40f2-98f7-f4de4dc27fc4", | ||
"appType": "app", | ||
"appDisplayName": "boilerplate", | ||
"iconFile": "resources/icon.png", | ||
"wipeColor": "#607d8b", | ||
"requestedPermissions": [], | ||
"i18n": { | ||
"en": { | ||
"name": "boilerplate" | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<svg> | ||
<link rel="import" href="screen1.gui" /> | ||
<link rel="import" href="screen2.gui" /> | ||
</svg> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<svg id="screen-1" display="none"> | ||
<text id="minutes">--</text> | ||
<text id="seconds" x="50">--</text> | ||
</svg> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<svg id="screen-2" display="none"> | ||
<text>Screen 2</text> | ||
</svg> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
text { | ||
font-size: 32; | ||
font-family: System-Regular; | ||
font-weight: regular; | ||
text-length: 32; | ||
fill: white; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<svg> | ||
<defs> | ||
<link rel="stylesheet" href="styles.css" /> | ||
<link rel="import" href="/mnt/sysassets/widgets_common.gui" /> | ||
</defs> | ||
</svg> |