Skip to content

Commit c96501e

Browse files
committed
Refactor into core cycle-free module
1 parent 25d45ff commit c96501e

16 files changed

Lines changed: 1060 additions & 180 deletions

js/ui/BUILD

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@ package(default_visibility = ["//visibility:public"])
33
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library", "closure_js_test")
44

55
closure_js_library(
6-
name = "component",
6+
name = "core",
77
srcs = [
8-
"app.js",
9-
"component.js",
10-
"route.js",
11-
"route/event.js",
12-
"router.js",
8+
"core.js",
139
],
1410
deps = [
1511
":history",
1612
":keyboard",
1713
":injector",
1814
"@io_bazel_rules_closure//closure/library/asserts",
1915
"@io_bazel_rules_closure//closure/library/dom",
20-
"@io_bazel_rules_closure//closure/library/events:event",
16+
"@io_bazel_rules_closure//closure/library/events",
2117
"@io_bazel_rules_closure//closure/library/events:eventhandler",
2218
"@io_bazel_rules_closure//closure/library/events:eventtarget",
2319
"@io_bazel_rules_closure//closure/library/fx:dom",
2420
"@io_bazel_rules_closure//closure/library/fx:easing",
21+
"@io_bazel_rules_closure//closure/library/history:event",
2522
"@io_bazel_rules_closure//closure/library/history:eventtype",
2623
"@io_bazel_rules_closure//closure/library/object",
2724
"@io_bazel_rules_closure//closure/library/promise",
25+
"@io_bazel_rules_closure//closure/library/promise:resolver",
2826
"@io_bazel_rules_closure//closure/library/string",
2927
"@io_bazel_rules_closure//closure/library/style",
3028
"@io_bazel_rules_closure//closure/library/ui:component",
@@ -46,6 +44,7 @@ closure_js_library(
4644
"@io_bazel_rules_closure//closure/library/events:event",
4745
"@io_bazel_rules_closure//closure/library/events:eventtarget",
4846
"@io_bazel_rules_closure//closure/library/events:eventtype",
47+
"@io_bazel_rules_closure//closure/library/history:event",
4948
"@io_bazel_rules_closure//closure/library/history:eventtype",
5049
"@io_bazel_rules_closure//closure/library/history:html5history",
5150
"@io_bazel_rules_closure//closure/library/string",
@@ -71,8 +70,9 @@ closure_js_library(
7170
"template.js",
7271
],
7372
deps = [
74-
":component",
73+
":core",
7574
"@io_bazel_rules_closure//closure/library/soy",
75+
"@io_bazel_rules_closure//closure/library/dom",
7676
],
7777
)
7878

@@ -85,7 +85,7 @@ closure_js_library(
8585
"tabs.js",
8686
],
8787
deps = [
88-
":component",
88+
":core",
8989
"@io_bazel_rules_closure//closure/library/asserts",
9090
"@io_bazel_rules_closure//closure/library/dom",
9191
"@io_bazel_rules_closure//closure/library/dom:classlist",
@@ -105,7 +105,9 @@ closure_js_library(
105105
"@io_bazel_rules_closure//closure/library/dom",
106106
"@io_bazel_rules_closure//closure/library/math:coordinate",
107107
"@io_bazel_rules_closure//closure/library/style",
108+
"@io_bazel_rules_closure//closure/library/events",
108109
"@io_bazel_rules_closure//closure/library/ui:component",
110+
"@io_bazel_rules_closure//closure/library/ui:container",
109111
"@io_bazel_rules_closure//closure/library/ui:menu",
110112
"@io_bazel_rules_closure//closure/library/ui:menubutton",
111113
"@io_bazel_rules_closure//closure/library/ui:submenu",
@@ -119,38 +121,28 @@ closure_js_library(
119121
"syntax.js",
120122
],
121123
deps = [
122-
":component",
124+
":core",
123125
"@io_bazel_rules_closure//closure/library/asserts",
124126
"@io_bazel_rules_closure//closure/library/dom",
125127
],
126128
)
127129

128-
# closure_js_library(
129-
# name = "app",
130-
# srcs = [
131-
# ],
132-
# deps = [
133-
# ":component",
134-
# ],
135-
# )
136130

137131
closure_js_library(
138132
name = "injector",
139133
srcs = [
140134
"injector.js",
141135
],
142136
deps = [
143-
# ":component",
137+
# ":core",
144138
],
145139
)
146140

147141
closure_js_library(
148142
name = "ui",
149-
# srcs = [
150-
# ],
151143
exports = [
152144
":injector",
153-
":component",
145+
":core",
154146
":history",
155147
":keyboard",
156148
":menushield",
@@ -185,7 +177,7 @@ closure_js_test(
185177
],
186178
entry_points = ["goog:stack.ui.RouteTest"],
187179
deps = [
188-
":component",
180+
":core",
189181
":select",
190182
":app",
191183
# "@io_bazel_rules_closure//closure/library",

js/ui/app.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ goog.module('stack.ui.App');
22

33
const BzlHistory = goog.require('stack.ui.History');
44
const Component = goog.require('stack.ui.Component');
5-
const HEventType = goog.require('goog.history.EventType');
6-
const Injector = goog.require('stack.ui.Injector');
5+
const HistoryEvent = goog.require('goog.history.Event');
6+
const HistoryEventType = goog.require('goog.history.EventType');
7+
const Injector = goog.require('stack.ui.Injector');
78
const Keyboard = goog.require('stack.ui.Keyboard');
8-
const Promise_ = goog.require('goog.Promise');
9-
const Router = goog.require('stack.ui.Router');
10-
const asserts = goog.require('goog.asserts');
11-
const dom = goog.require('goog.dom');
12-
const objects = goog.require('goog.object');
9+
const Promise_ = goog.require('goog.Promise');
10+
const Route = goog.require('stack.ui.Route');
11+
const Router = goog.require('stack.ui.Router');
12+
const asserts = goog.require('goog.asserts');
13+
const dom = goog.require('goog.dom');
14+
const objects = goog.require('goog.object');
1315

1416

1517
class App extends Component {
@@ -25,7 +27,7 @@ class App extends Component {
2527
* @type {!Injector}
2628
*/
2729
this.injector_ = new Injector();
28-
30+
2931
/**
3032
* A registry of components that can be accessed by a common name.
3133
* @const @private
@@ -35,7 +37,7 @@ class App extends Component {
3537

3638
/** @const @private @type {!BzlHistory} */
3739
this.history_ = new BzlHistory();
38-
this.getHandler().listen(this.history_, HEventType.NAVIGATE, this.handleHistoryNavigate);
40+
this.getHandler().listen(this.history_, HistoryEventType.NAVIGATE, this.handleHistoryNavigate);
3941
this.registerDisposable(this.history_);
4042

4143
/** @const @private @type {!Keyboard} */
@@ -50,16 +52,16 @@ class App extends Component {
5052
start() {
5153
this.history_.setEnabled(true);
5254
}
53-
55+
5456
/**
55-
* @param {!goog.history.Event} e
57+
* @param {!HistoryEvent} e
5658
*/
5759
handleHistoryNavigate(e) {
5860
this.router_.go(e.token).thenCatch(err => {
5961
console.warn(`Routing failure while nagivating to ${e.token}`);
6062
});
6163
}
62-
64+
6365
/**
6466
* @param {!Component} c
6567
* @param {!boolean} b
@@ -71,14 +73,14 @@ class App extends Component {
7173
console.warn("Stop Loaded " + c.getPathUrl());
7274
}
7375
}
74-
76+
7577
/**
7678
* @return {!Keyboard}
7779
*/
7880
getKbd() {
7981
return this.kbd_;
8082
}
81-
83+
8284
/**
8385
* @return {!Router}
8486
*/
@@ -92,7 +94,7 @@ class App extends Component {
9294
getInjector() {
9395
return this.injector_;
9496
}
95-
97+
9698
/**
9799
* @param {string} msg
98100
*/
@@ -138,8 +140,8 @@ class App extends Component {
138140
//route.touch(this);
139141
super.go(route);
140142
}
141-
142-
/** @param {!stack.ui.Route} route */
143+
144+
/** @param {!Route} route */
143145
handle404(route) {
144146
this.notifyError("404 (Not Found): " + route.getPath());
145147
}
@@ -157,7 +159,7 @@ class App extends Component {
157159
* will loopback on this object to the go() method.
158160
*
159161
* @param {string} path
160-
* @return {!Promise_<!stack.ui.Route>}
162+
* @return {!Promise_<!Route>}
161163
*/
162164
route(path) {
163165
return this.router_.go(path).thenCatch(err => {

js/ui/body.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const soy = goog.require('goog.soy');
1010
class Body extends Select {
1111

1212
/**
13-
* @param {?goog.dom.DomHelper=} opt_domHelper
13+
* @param {?dom.DomHelper=} opt_domHelper
1414
*/
1515
constructor(opt_domHelper) {
1616
super(opt_domHelper);
1717
this.addTab('home', new Home());
1818
this.addTab('search', new List());
1919
}
20-
20+
2121
/**
2222
* Modifies behavior to use touch rather than progress to
2323
* not advance the path pointer.
@@ -38,7 +38,7 @@ class Body extends Select {
3838
goHere(route) {
3939
this.select('home', route.add('home'));
4040
}
41-
41+
4242
/**
4343
* @override
4444
*/
@@ -55,7 +55,7 @@ class Body extends Select {
5555
super.enterDocument();
5656
this.addChild(new Menu(this.getTabStrict('search'), this.getDomHelper()), true);
5757
}
58-
58+
5959
}
6060

6161
exports = Body;

js/ui/component.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ goog.module('stack.ui.Component');
66
const BgColorTransform = goog.require('goog.fx.dom.BgColorTransform');
77
const ComponentEventType = goog.require('goog.ui.Component.EventType');
88
const GoogUiComponent = goog.require('goog.ui.Component');
9-
const Route = goog.require('stack.ui.Route');
9+
const GoogUiControl = goog.require('goog.ui.Control');
10+
// const Route = goog.require('stack.ui.Route');
1011
const asserts = goog.require('goog.asserts');
1112
const easing = goog.require('goog.fx.easing');
1213
const strings = goog.require('goog.string');
@@ -18,7 +19,7 @@ const style = goog.require('goog.style');
1819
class Component extends GoogUiComponent {
1920

2021
/**
21-
* @param {?goog.dom.DomHelper=} opt_domHelper
22+
* @param {?dom.DomHelper=} opt_domHelper
2223
*/
2324
constructor(opt_domHelper) {
2425
super(opt_domHelper);
@@ -65,8 +66,8 @@ class Component extends GoogUiComponent {
6566
var name = current.getName();
6667
if (name) {
6768
path.push(name);
68-
// } else {
69-
// console.log('path: no name', current);
69+
// } else {
70+
// console.log('path: no name', current);
7071
}
7172
current = current.parent();
7273
}
@@ -111,10 +112,10 @@ class Component extends GoogUiComponent {
111112
}
112113

113114
/**
114-
* @return {?stack.ui.Component}
115+
* @return {?Component}
115116
*/
116117
parent() {
117-
return /** @type {?stack.ui.Component} */ (
118+
return /** @type {?Component} */ (
118119
this.getParent()
119120
);
120121
}
@@ -165,41 +166,41 @@ class Component extends GoogUiComponent {
165166

166167
/**
167168
* @param {string} id
168-
* @return {?stack.ui.Component}
169+
* @return {?Component}
169170
*/
170171
child(id) {
171-
return /** @type {?stack.ui.Component} */ (
172+
return /** @type {?Component} */ (
172173
this.getChild(id)
173174
);
174175
}
175176

176177
/**
177178
* @param {number} index
178-
* @return {!stack.ui.Component}
179+
* @return {!Component}
179180
*/
180181
childAt(index) {
181-
return /** @type {!stack.ui.Component} */ (
182+
return /** @type {!Component} */ (
182183
asserts.assertObject(this.getChildAt(index))
183184
);
184185
}
185186

186187
/**
187188
* @param {string} id
188-
* @return {!stack.ui.Component}
189+
* @return {!Component}
189190
*/
190191
strictchild(id) {
191-
return /** @type {!stack.ui.Component} */ (
192+
return /** @type {!Component} */ (
192193
asserts.assertObject(this.getChild(id))
193194
);
194195
}
195196

196197
/**
197198
* Return the root component.
198199
*
199-
* @return {!stack.ui.Component}
200+
* @return {!Component}
200201
*/
201202
getRoot() {
202-
/** @type {?stack.ui.Component} */
203+
/** @type {?Component} */
203204
let current = this;
204205
while (current) {
205206
if (!current.parent()) {
@@ -217,7 +218,7 @@ class Component extends GoogUiComponent {
217218
return /** @type {!stack.ui.App} */ (this.getRoot());
218219
}
219220

220-
221+
221222
/**
222223
* Default is no-op.
223224
*/
@@ -260,7 +261,7 @@ class Component extends GoogUiComponent {
260261
* @param {number=} opt_time Length of animation in milliseconds.
261262
* @param {?Function=} opt_accel Acceleration function, returns 0-1 for inputs 0-1.
262263
* @param {?Element=} opt_element Dom Node to be used in the animation.
263-
* @param {?goog.events.EventHandler=} opt_eventHandler Optional event handler
264+
* @param {?events.EventHandler=} opt_eventHandler Optional event handler
264265
* to use when listening for events.
265266
*/
266267
bgColorFadeIn(opt_start, opt_end, opt_time, opt_accel, opt_element, opt_eventHandler) {
@@ -296,7 +297,7 @@ class Component extends GoogUiComponent {
296297
}
297298

298299
/**
299-
* @return {?Array<!goog.ui.Control>}
300+
* @return {?Array<!GoogUiControl>}
300301
*/
301302
getMenuItems() {
302303
return null;

0 commit comments

Comments
 (0)