neo.mjs 7.0.6 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/apps/ServiceWorker.mjs +2 -2
- package/apps/portal/index.html +1 -1
- package/apps/portal/model/Content.mjs +3 -2
- package/apps/portal/model/Example.mjs +46 -0
- package/apps/portal/resources/data/examples_devmode.json +173 -0
- package/apps/portal/resources/data/examples_dist_dev.json +164 -0
- package/apps/portal/resources/data/examples_dist_prod.json +164 -0
- package/apps/portal/store/Examples.mjs +33 -0
- package/apps/portal/view/HeaderToolbar.mjs +3 -0
- package/apps/portal/view/Viewport.mjs +3 -2
- package/apps/portal/view/ViewportController.mjs +32 -14
- package/apps/portal/view/about/Container.mjs +2 -2
- package/apps/portal/view/blog/List.mjs +3 -3
- package/apps/portal/view/examples/List.mjs +122 -0
- package/apps/portal/view/examples/TabContainer.mjs +79 -0
- package/apps/portal/view/examples/TabContainerController.mjs +41 -0
- package/apps/portal/view/home/FooterContainer.mjs +1 -1
- package/apps/portal/view/home/parts/Features.mjs +5 -5
- package/apps/shareddialog/view/MainContainerController.mjs +37 -30
- package/examples/ServiceWorker.mjs +2 -2
- package/examples/todoList/version2/MainContainer.mjs +38 -48
- package/examples/todoList/version2/TodoList.mjs +6 -39
- package/examples/todoList/version2/TodoListModel.mjs +2 -2
- package/package.json +7 -7
- package/resources/data/deck/learnneo/pages/Welcome.md +0 -4
- package/resources/data/deck/learnneo/pages/guides/Forms.md +1 -0
- package/resources/data/deck/learnneo/pages/guides/InstanceLifecycle.md +1 -0
- package/resources/data/deck/learnneo/pages/guides/Layouts.md +1 -0
- package/resources/data/deck/learnneo/pages/guides/Mixins.md +1 -0
- package/resources/data/deck/learnneo/pages/guides/MultiWindow.md +1 -0
- package/resources/data/deck/learnneo/pages/guides/Tables.md +1 -0
- package/resources/data/deck/learnneo/pages/guides/events/DomEvents.md +263 -0
- package/resources/data/deck/learnneo/pages/{TodoList.md → tutorials/TodoList.md} +23 -33
- package/resources/data/deck/learnneo/tree.json +45 -48
- package/resources/scss/src/apps/portal/about/MemberContainer.scss +5 -4
- package/resources/scss/src/apps/portal/blog/Container.scss +2 -0
- package/resources/scss/src/apps/portal/examples/List.scss +157 -0
- package/resources/scss/src/apps/portal/examples/TabContainer.scss +36 -0
- package/resources/scss/src/button/Base.scss +4 -0
- package/resources/scss/src/calendar/view/calendars/ColorsList.scss +4 -0
- package/resources/scss/src/calendar/view/calendars/List.scss +2 -1
- package/resources/scss/src/dialog/Base.scss +2 -2
- package/resources/scss/src/list/Base.scss +3 -3
- package/resources/scss/theme-neo-light/button/Base.scss +3 -3
- package/src/DefaultConfig.mjs +2 -2
- package/src/calendar/view/MainContainer.mjs +7 -5
- package/src/calendar/view/calendars/EditContainer.mjs +3 -2
- package/src/calendar/view/calendars/List.mjs +1 -0
- package/src/calendar/view/week/Component.mjs +5 -3
- package/src/calendar/view/week/plugin/DragDrop.mjs +4 -3
- package/src/code/LivePreview.mjs +28 -1
- package/src/collection/Base.mjs +1 -0
- package/src/controller/Component.mjs +10 -10
- package/src/core/Observable.mjs +4 -27
- package/src/grid/View.mjs +82 -0
- package/src/layout/Cube.mjs +44 -38
- package/src/list/Base.mjs +16 -0
- package/src/main/addon/DragDrop.mjs +3 -2
- package/src/manager/DomEvent.mjs +30 -18
- package/src/table/View.mjs +82 -0
- package/src/util/Function.mjs +24 -0
- package/resources/data/deck/learnneo/pages/2023-10-08T20-37-30-658Z.md +0 -0
- package/resources/data/deck/learnneo/pages/2023-10-08T22-22-11-013Z.md +0 -0
- package/resources/data/deck/learnneo/pages/Earthquakes-01-goals.md +0 -32
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-01-generate-a-workspace.md +0 -47
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-02-generate-the-starter-app.md +0 -150
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-03-debugging.md +0 -136
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-04-fetch-data.md +0 -146
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-05-refactor-the-table.md +0 -146
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-06-use-a-view-model.md +0 -301
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-07-use-the-google-maps-addon.md +0 -175
- package/resources/data/deck/learnneo/pages/Earthquakes-Lab-08-events.md +0 -38
- package/resources/data/deck/learnneo/pages/TestLivePreview.md +0 -32
- package/resources/data/deck/learnneo/pages/WhatAboutHTML.md +0 -1
- package/resources/data/deck/learnneo/pages/stylesheet.md +0 -57
- /package/resources/data/deck/learnneo/pages/{WhyNeo-Effort.md → benefits/Effort.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{WhyNeo-Features.md → benefits/Features.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{WhyNeo-Intro.md → benefits/Introduction.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{WhyNeo-Multi-Window.md → benefits/Multi-Window.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{WhyNeo-Quick.md → benefits/Quick.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{WhyNeo-Speed.md → benefits/Speed.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{ComponentModels.md → gettingstarted/ComponentModels.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{Config.md → gettingstarted/Config.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{DescribingTheUI.md → gettingstarted/DescribingTheUI.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{Events.md → gettingstarted/Events.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{Extending.md → gettingstarted/Extending.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{References.md → gettingstarted/References.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{Setup.md → gettingstarted/Setup.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{2023-10-14T19-25-08-153Z.md → gettingstarted/Workspaces.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{ComponentsAndContainers.md → guides/ComponentsAndContainers.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{CustomComponents.md → guides/CustomComponents.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{MainThreadAddonExample.md → guides/MainThreadAddonExample.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{MainThreadAddonIntro.md → guides/MainThreadAddonIntro.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{GuideViewModels.md → guides/ViewModels.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{GuideEvents.md → guides/events/CustomEvents.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{2023-10-08T20-20-37-336Z.md → javascript/ClassFeatures.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{2023-10-07T19-18-28-517Z.md → javascript/Classes.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{2023-10-31T13-59-37-550Z.md → javascript/NewNode.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{2023-10-08T20-20-07-934Z.md → javascript/Overrides.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{2023-10-08T21-58-25-809Z.md → javascript/Super.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{Earthquakes.md → tutorials/Earthquakes.md} +0 -0
- /package/resources/data/deck/learnneo/pages/{RSP.md → tutorials/RSP.md} +0 -0
@@ -1,47 +0,0 @@
|
|
1
|
-
In this lab, you'll generate a Neo.mjs workspace and run the starter app.
|
2
|
-
|
3
|
-
<details>
|
4
|
-
<summary>Wait!</summary>
|
5
|
-
You may already have a workspace! If so, you can skip this lab. For example, if you followed the <a href="#/learn/Setup">Getting Started > Setup</a> topic, above, you should already have a workspace.
|
6
|
-
|
7
|
-
If you don't have a workspace, then continue on to the next step.
|
8
|
-
</details>
|
9
|
-
|
10
|
-
<details>
|
11
|
-
<summary>Use the command-line to generate the workspace</summary>
|
12
|
-
|
13
|
-
Use a terminal window to navigate to some parent folder,
|
14
|
-
then run
|
15
|
-
|
16
|
-
npx neo-app@latest
|
17
|
-
|
18
|
-
You'll be prompted for a workspace name, starter app name, etc — accept the default for everything.
|
19
|
-
As the command finishes it starts a server and opens a browser window.
|
20
|
-
</details>
|
21
|
-
|
22
|
-
<details>
|
23
|
-
<summary>Inspect the workspace</summary>
|
24
|
-
|
25
|
-
The workspace contains a local copy of the API docs, an `apps` directory (where your apps are found),
|
26
|
-
and some other directories.
|
27
|
-
</details>
|
28
|
-
|
29
|
-
<details>
|
30
|
-
<summary>Start the server</summary>
|
31
|
-
From the root of the `workspace` start the server via `npm run server-start`. That starts a server
|
32
|
-
at port 8080 and opens a new browser window.
|
33
|
-
|
34
|
-
<img src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/StartServer.png" style="width:80%"/>
|
35
|
-
|
36
|
-
</details>
|
37
|
-
|
38
|
-
|
39
|
-
<details>
|
40
|
-
<summary>Run the starter app</summary>
|
41
|
-
|
42
|
-
By default, an app named `myapp` was created. You can run it by entering the `apps` directory and
|
43
|
-
clicking `myapp`. It's a folder containing an `index.html` along with the source code for the app.
|
44
|
-
|
45
|
-
<img src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/RunTheStarterApp.png" style="width:80%"/>
|
46
|
-
|
47
|
-
</details>
|
@@ -1,150 +0,0 @@
|
|
1
|
-
In this lab you'll create a starter app and add a single component.
|
2
|
-
|
3
|
-
<details>
|
4
|
-
|
5
|
-
<summary>Use the command-line to create a starter app</summary>
|
6
|
-
|
7
|
-
Use a terminal window to navigate to the workspace and run the following script. Use "Earthquakes"
|
8
|
-
as the app name, and defaults for everything else.
|
9
|
-
|
10
|
-
npm run create-app-minimal
|
11
|
-
|
12
|
-
After the script runs yous should see these files in the `app/earthquakes` directory.
|
13
|
-
|
14
|
-
`view/MainContainer.mjs`
|
15
|
-
- `app.mjs`
|
16
|
-
- `index.html`
|
17
|
-
- `neo-config.json`
|
18
|
-
|
19
|
-
If you look in `neo-config.json` you should see this content. Note the `mainThreadAddons` block
|
20
|
-
— it reflects the add-ons you chose when you followed the instructions in the script.
|
21
|
-
<pre>
|
22
|
-
{
|
23
|
-
"appPath": "../../apps/earthquakes/app.mjs",
|
24
|
-
"basePath": "../../",
|
25
|
-
"environment": "development",
|
26
|
-
"mainPath": "../node_modules/neo.mjs/src/Main.mjs",
|
27
|
-
"mainThreadAddons": [
|
28
|
-
"DragDrop",
|
29
|
-
"Stylesheet"
|
30
|
-
],
|
31
|
-
"workerBasePath": "../../node_modules/neo.mjs/src/worker/"
|
32
|
-
}</pre>
|
33
|
-
|
34
|
-
You're free to edit `neo-config.json` if you were to change your mind later about the theme or need for other add-ons.
|
35
|
-
|
36
|
-
If you refresh browser at <a href="http://localhost:8080/apps/" target="apps">http://localhost:8080/apps/</a>
|
37
|
-
you'll see the new _earthquakes_ app listed, and if you run it you'll see... nothing! That's because the
|
38
|
-
minimal starter app is the shell of an application without any view content. We'll add a little content
|
39
|
-
later in the lab.
|
40
|
-
|
41
|
-
<img style="width:80%" src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/EmptyEarthquakes.png"></img>
|
42
|
-
|
43
|
-
</details>
|
44
|
-
|
45
|
-
<details>
|
46
|
-
<summary>Look at the main view source</summary>
|
47
|
-
|
48
|
-
Use a code editor and look at `workspace/apps/earthquakes/src/view/MainView.mjs`. You'll see the
|
49
|
-
following class definition:
|
50
|
-
|
51
|
-
<pre data-javascript>
|
52
|
-
|
53
|
-
import Base from '../../../node_modules/neo.mjs/src/container/Base.mjs';
|
54
|
-
import Controller from './MainViewController.mjs';
|
55
|
-
import ViewModel from './MainViewModel.mjs';
|
56
|
-
|
57
|
-
class MainView extends Base {
|
58
|
-
static config = {
|
59
|
-
className: 'Earthquakes.view.MainView',
|
60
|
-
ntype: 'earthquakes-main',
|
61
|
-
|
62
|
-
controller: {module: Controller},
|
63
|
-
model: {module: ViewModel},
|
64
|
-
|
65
|
-
layout: {ntype: 'fit'},
|
66
|
-
items: [],
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
Neo.setupClass(MainView);
|
71
|
-
|
72
|
-
export default MainView;
|
73
|
-
</pre>
|
74
|
-
|
75
|
-
As you can see, `MainView extends Base`, and `Base` is a _container_ (`Neo.container.Base`).
|
76
|
-
A container is a component — it holds other components, specified in `items:[]`. There
|
77
|
-
are no items in the starter app. The `layout` config specifies how the items are arranged.
|
78
|
-
|
79
|
-
</details>
|
80
|
-
|
81
|
-
<details>
|
82
|
-
<summary>Add a component</summary>
|
83
|
-
|
84
|
-
Let's add a button. To do that, add an import for the button base class, then configure it
|
85
|
-
in the container's `items:[]`. If you were to read the API docs for buttons, you'd see
|
86
|
-
that buttons have various configs, such as `text`, which is the button text, `iconCls`, which
|
87
|
-
is typically a FontAwesome CSS class used to show an icon, and `handler`, which specifies
|
88
|
-
which method to run when the button is clicked. We'll use `text`.
|
89
|
-
|
90
|
-
<pre data-javascript>
|
91
|
-
|
92
|
-
import Base from '../../../node_modules/neo.mjs/src/container/Base.mjs';
|
93
|
-
import Button from '../../../node_modules/neo.mjs/src/button/Base.mjs';
|
94
|
-
import Controller from './MainViewController.mjs';
|
95
|
-
import ViewModel from './MainViewModel.mjs';
|
96
|
-
|
97
|
-
class MainView extends Base {
|
98
|
-
static config = {
|
99
|
-
className: 'Earthquakes.view.MainView',
|
100
|
-
ntype: 'earthquakes-main',
|
101
|
-
|
102
|
-
controller: {module: Controller},
|
103
|
-
model: {module: ViewModel},
|
104
|
-
|
105
|
-
layout: {ntype: 'fit'},
|
106
|
-
items: [{
|
107
|
-
module: Button,
|
108
|
-
text: 'Button!'
|
109
|
-
}],
|
110
|
-
}
|
111
|
-
}
|
112
|
-
|
113
|
-
Neo.setupClass(MainView);
|
114
|
-
|
115
|
-
export default MainView;
|
116
|
-
</pre>
|
117
|
-
|
118
|
-
|
119
|
-
When you run the app you'll see the single button.
|
120
|
-
|
121
|
-
<img src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/EarthquakesSingleFitButton.png" style="width:80%"/>
|
122
|
-
|
123
|
-
The button takes up the full width. Buttons look different depending on the theme. We're using
|
124
|
-
the _neo-theme-neo-light_ theme, which controls button height. Otherwise, child items a using the _fit_ layout
|
125
|
-
take up the full window.
|
126
|
-
</details>
|
127
|
-
|
128
|
-
|
129
|
-
<details>
|
130
|
-
<summary>Modify the layout</summary>
|
131
|
-
The `layout` configures how child items are visually arranged. First, note that the config
|
132
|
-
specifies `ntype`. We used `module` for the button config. An `ntype` is a class alias — if a class
|
133
|
-
has already been imported, you can use the `ntype` rather than importing it again and using the `module`
|
134
|
-
config. We haven't imported any layouts, but it turns out that `Neo.container.Base` _does_ import all the
|
135
|
-
layout types, which means we're always free to use `ntype` with layouts. You're free to specify an `ntype`
|
136
|
-
for the classes you define.
|
137
|
-
|
138
|
-
Let's change the layout to arrange items vertically, with items aligned horizontally at the start.
|
139
|
-
|
140
|
-
<pre data-javascript>
|
141
|
-
layout: {
|
142
|
-
ntype: 'vbox',
|
143
|
-
align: 'start'
|
144
|
-
}
|
145
|
-
</pre>
|
146
|
-
|
147
|
-
<img src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/EarthquakesSingleVoxStartButton.png" style="width:80%"/>
|
148
|
-
|
149
|
-
|
150
|
-
</details>
|
@@ -1,136 +0,0 @@
|
|
1
|
-
In this lab you'll get a little debugging practice by getting component references, changing properties,
|
2
|
-
and runing methods.
|
3
|
-
|
4
|
-
Remember that when using the debugger console you need to be in the _neo-app-worker_ context.
|
5
|
-
|
6
|
-
<details>
|
7
|
-
<summary>Use `Neo.manager.Component.items`</summary>
|
8
|
-
|
9
|
-
While running the _earthquakes_ app, open Chrome devtools, choose the _neomjs-app-worker_ JavaScript
|
10
|
-
context, and run this statement:
|
11
|
-
|
12
|
-
Neo.manager.Component.items
|
13
|
-
|
14
|
-
The `items` property is an array of all created components. The array may have a lot of entries, depending on
|
15
|
-
the complexity of an app and how much you've done while running it. But it's an easy way to explore what's
|
16
|
-
been created.
|
17
|
-
|
18
|
-
</details>
|
19
|
-
|
20
|
-
<details>
|
21
|
-
<summary>Store as global variable</summary>
|
22
|
-
|
23
|
-
Any time you have a object reference in the console — even if it's nested within an array or object —
|
24
|
-
you can right click on the object and choose _Store as global_ variable. Chrome will create a variable named
|
25
|
-
`temp1`, `temp2`, etc., that references the object. That can make it easier to inspect the object and run its methods..
|
26
|
-
|
27
|
-
|
28
|
-
<img src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/StoreAsGlobal.png" style="width:80%"/>
|
29
|
-
|
30
|
-
</details>
|
31
|
-
|
32
|
-
|
33
|
-
<details>
|
34
|
-
<summary>Use `Neo.find()` and `Neo.findFirst()`</summary>
|
35
|
-
|
36
|
-
If you know what you're looking for, and don't want to bother inspecting everything in `Neo.manager.Component.items`,
|
37
|
-
you can use `Neo.find()`, passing an object used to match against what you're searching for.
|
38
|
-
|
39
|
-
`Neo.find()` returns an array of matching instances, and `Neo.findFirst()` returns the first matching item.
|
40
|
-
Often you know there's only a single instance, so in practice `Neo.findFirst()` is more commonly used.
|
41
|
-
|
42
|
-
You could find the button via Neo.find({ntype:'button'}) or Neo.find({text:'Button!'} (assuming you haven't changed
|
43
|
-
the button's text.) You can even match a property you give the button. For example, if you configured it with a made-up
|
44
|
-
property `foo:true`, you could find it via `Neo.findFirst({foo:true})`. The point is you can search for any properties
|
45
|
-
you'd like.
|
46
|
-
|
47
|
-
Try this out.
|
48
|
-
|
49
|
-
`Neo.findFirst({text:'Button!'}).text = 'Foo!'
|
50
|
-
|
51
|
-
You should see the button's text change immediately.
|
52
|
-
|
53
|
-
</details>
|
54
|
-
|
55
|
-
|
56
|
-
<details>
|
57
|
-
<summary>Use `Shift-Ctrl-right-click`</summary>
|
58
|
-
|
59
|
-
With your cursor over the button, press _Shift-Ctrl-right-click_. The console will log the button, its parent `MainView`
|
60
|
-
and the subsequent parent `Viewport. The button reference shows up as `Base` because the button class name is `Neo.button.Base`.
|
61
|
-
|
62
|
-
<img width="80%" src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/EarthquakesDemoShiftCtrl.png">
|
63
|
-
|
64
|
-
Note that _Shift-Ctrl-right-click_ is only available during development — it isn't available in a build.
|
65
|
-
|
66
|
-
</details>
|
67
|
-
|
68
|
-
|
69
|
-
<details>
|
70
|
-
<summary>Add a method</summary>
|
71
|
-
|
72
|
-
As we mentioned, when debugging, if you a have a reference you can access or update its properties, or run
|
73
|
-
its methods. Let's try that out by adding a method.
|
74
|
-
|
75
|
-
Edit `apps/earthquakes/view/MainView.mjs` and add a method.
|
76
|
-
|
77
|
-
<pre data-javascript>
|
78
|
-
|
79
|
-
import Base from '../../../node_modules/neo.mjs/src/container/Base.mjs';
|
80
|
-
import Button from '../../../node_modules/neo.mjs/src/button/Base.mjs';
|
81
|
-
import Controller from './MainViewController.mjs';
|
82
|
-
import ViewModel from './MainViewModel.mjs';
|
83
|
-
|
84
|
-
class MainView extends Base {
|
85
|
-
static config = {
|
86
|
-
className: 'Earthquakes.view.MainView',
|
87
|
-
ntype: 'earthquakes-main',
|
88
|
-
|
89
|
-
controller: {module: Controller},
|
90
|
-
model: {module: ViewModel},
|
91
|
-
|
92
|
-
layout: {
|
93
|
-
ntype: 'vbox',
|
94
|
-
align: 'start'
|
95
|
-
},
|
96
|
-
items: [{
|
97
|
-
module: Button,
|
98
|
-
foo: true,
|
99
|
-
text: 'Button!'
|
100
|
-
}],
|
101
|
-
}
|
102
|
-
doFoo() {
|
103
|
-
console.log('foo!');
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
Neo.setupClass(MainView);
|
108
|
-
|
109
|
-
export default MainView;
|
110
|
-
</pre>
|
111
|
-
|
112
|
-
Save your changes.
|
113
|
-
|
114
|
-
As you can see, the code defined an instance method `doFoo()` that simply logs a message. We'll run the method via debugging techniques in the next step.
|
115
|
-
|
116
|
-
</details>
|
117
|
-
|
118
|
-
<details>
|
119
|
-
<summary>Use `Neo.component.Manager.items` to run the method</summary>
|
120
|
-
|
121
|
-
On the console run `Neo.component.Manager.items`. Expand the array and right-click on the entry for `MainView` and
|
122
|
-
choose `Store object as global variable`. Then type `temp1.doFoo()` — you should see "foo!" being logged.
|
123
|
-
|
124
|
-
Remember that you _must_ run console statement in the _neomjs-app-worker_ context, and every time your choose
|
125
|
-
`Store object as global variable` it'll increment the name of the temp variable: `temp1`, `temp2`, etc.
|
126
|
-
</details>
|
127
|
-
|
128
|
-
<details>
|
129
|
-
<summary>Use _Shift-Ctrl-right-click_ to run the method</summary>
|
130
|
-
|
131
|
-
Now try the _Shift-Ctrl-right-click_ technique.
|
132
|
-
|
133
|
-
With your cursor over the button, do a _Shift-Ctrl-right-click_ — you'll see the component hierarchy logged.
|
134
|
-
As you did in the previous step, right-click on the entry for `MainView` and choose `Store object as global variable`.
|
135
|
-
Then run `doFoo()` using that variable.
|
136
|
-
</details>
|
@@ -1,146 +0,0 @@
|
|
1
|
-
<details>
|
2
|
-
<summary>Copy the table into its own class</summary>
|
3
|
-
|
4
|
-
Create a new file named `apps/earthquakes/view/earthquakes/Table.mjs` with this content.
|
5
|
-
|
6
|
-
<pre data-javascript>
|
7
|
-
import Base from '../../../../node_modules/neo.mjs/src/table/Container.mjs';
|
8
|
-
|
9
|
-
class Table extends Base {
|
10
|
-
static config = {
|
11
|
-
className: 'Earthquakes.view.earthquakes.Table',
|
12
|
-
ntype: 'earthquakes-table',
|
13
|
-
layout: {ntype: 'vbox', align: 'stretch'},
|
14
|
-
style: {width: '100%'},
|
15
|
-
columns: [{
|
16
|
-
dataField: "timestamp",
|
17
|
-
text: "Date",
|
18
|
-
renderer: (data) => data.value.toLocaleDateString(undefined, {weekday: "long", year: "numeric", month: "long", day: "numeric"}),
|
19
|
-
}, {
|
20
|
-
dataField: "humanReadableLocation",
|
21
|
-
text: "Location",
|
22
|
-
}, {
|
23
|
-
dataField: "size",
|
24
|
-
text: "Magnitude",
|
25
|
-
align: "right",
|
26
|
-
renderer: (data) => data.value.toLocaleString(),
|
27
|
-
}],
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
Neo.setupClass(Table);
|
32
|
-
|
33
|
-
export default Table;
|
34
|
-
</pre>
|
35
|
-
|
36
|
-
</details>
|
37
|
-
|
38
|
-
<details>
|
39
|
-
<summary>Review the code</summary>
|
40
|
-
|
41
|
-
- The class extends `Neo.table.Container`
|
42
|
-
- It has an `ntype`, which we can use when creating an instance, or when debugging
|
43
|
-
- Each column has `text` and `dataField` configs, and some have renderers
|
44
|
-
|
45
|
-
</details>
|
46
|
-
|
47
|
-
<details>
|
48
|
-
<summary>Use the new component</summary>
|
49
|
-
|
50
|
-
Edit `apps/earthquakes/view/MainView` and make these changes.
|
51
|
-
|
52
|
-
- Add `import EarthquakesTable from './earthquakes/Table.mjs';`
|
53
|
-
- Replace the `module: Table` with `module: EarthquakesTable`
|
54
|
-
- Remove the `columns:[]` config
|
55
|
-
- Leave the `store` config alone
|
56
|
-
|
57
|
-
Save and refresh the browser, and your app should run as before.
|
58
|
-
|
59
|
-
You can confim that the new class _is being loaded_ by using DevTools to try to open `earthquakes/Table` — if it
|
60
|
-
was imported, it'll be listed.
|
61
|
-
|
62
|
-
You can confirm that an instance _was created_ by using the DevTools console and searching for it via
|
63
|
-
|
64
|
-
Neo.first('earthquakes-table')
|
65
|
-
|
66
|
-
</details>
|
67
|
-
|
68
|
-
<details>
|
69
|
-
<summary>Here's the code</summary>
|
70
|
-
|
71
|
-
<pre data-javascript>
|
72
|
-
import Base from '../../../node_modules/neo.mjs/src/container/Base.mjs';
|
73
|
-
import Controller from './MainViewController.mjs';
|
74
|
-
import EarthquakesTable from './earthquakes/Table.mjs';
|
75
|
-
import Store from '../../../node_modules/neo.mjs/src/data/Store.mjs';
|
76
|
-
import ViewModel from './MainViewModel.mjs';
|
77
|
-
|
78
|
-
class MainView extends Base {
|
79
|
-
static config = {
|
80
|
-
className: 'Earthquakes.view.MainView',
|
81
|
-
ntype: 'earthquakes-main',
|
82
|
-
|
83
|
-
controller: {module: Controller},
|
84
|
-
model: {module: ViewModel},
|
85
|
-
|
86
|
-
layout: {ntype: 'vbox', align: 'stretch'},
|
87
|
-
items: [{
|
88
|
-
module: EarthquakesTable,
|
89
|
-
store: {
|
90
|
-
module: Store,
|
91
|
-
model: {
|
92
|
-
fields: [{
|
93
|
-
name: "humanReadableLocation",
|
94
|
-
}, {
|
95
|
-
name: "size",
|
96
|
-
}, {
|
97
|
-
name: "timestamp",
|
98
|
-
type: "Date",
|
99
|
-
}],
|
100
|
-
},
|
101
|
-
url: "https://apis.is/earthquake/is",
|
102
|
-
responseRoot: "results",
|
103
|
-
autoLoad: true,
|
104
|
-
},
|
105
|
-
style: {width: '100%'},
|
106
|
-
}],
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
Neo.setupClass(MainView);
|
111
|
-
|
112
|
-
export default MainView;
|
113
|
-
</pre>
|
114
|
-
|
115
|
-
</details>
|
116
|
-
|
117
|
-
<details>
|
118
|
-
<summary>Why are some things in `MainView` and not in `Table`?</summary>
|
119
|
-
|
120
|
-
When we refactored the table into its own class we didn't move all the configs. Both
|
121
|
-
the width styling and `store` were left in `MainView`. Why?
|
122
|
-
|
123
|
-
It's a matter of re-use and what you need in a given situation. By leaving the width specification
|
124
|
-
outside the table class we're to specify a different value in all the places we're using the table.
|
125
|
-
|
126
|
-
Similarly, if the store were in the table class, it would be using that specific store and
|
127
|
-
each instance of the table would have its own instance of the store. If we want multiple
|
128
|
-
instance of the table with each using a different store — or if
|
129
|
-
we wanted to share the store with other components — then it makes sense for the
|
130
|
-
store to be outside the table class.
|
131
|
-
|
132
|
-
</details>
|
133
|
-
|
134
|
-
<details>
|
135
|
-
<summary>Make a second instance of the table</summary>
|
136
|
-
|
137
|
-
To further illustrate that the table is reusable, let's create a second instance.
|
138
|
-
|
139
|
-
Simply copy-and-paste the value in the `MainView` `items` with an identical second item.
|
140
|
-
|
141
|
-
Save and refresh and you should see two tables.
|
142
|
-
|
143
|
-
<img style="width:80%" src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/EarthquakesTwoTables.png"></img>
|
144
|
-
|
145
|
-
</details>
|
146
|
-
|
@@ -1,146 +0,0 @@
|
|
1
|
-
<details>
|
2
|
-
<summary>Copy the table into its own class</summary>
|
3
|
-
|
4
|
-
Create a new file named `apps/earthquakes/view/earthquakes/Table.mjs` with this content.
|
5
|
-
|
6
|
-
<pre data-javascript>
|
7
|
-
import Base from '../../../../node_modules/neo.mjs/src/table/Container.mjs';
|
8
|
-
|
9
|
-
class Table extends Base {
|
10
|
-
static config = {
|
11
|
-
className: 'Earthquakes.view.earthquakes.Table',
|
12
|
-
ntype: 'earthquakes-table',
|
13
|
-
layout: {ntype: 'vbox', align: 'stretch'},
|
14
|
-
style: {width: '100%'},
|
15
|
-
columns: [{
|
16
|
-
dataField: "timestamp",
|
17
|
-
text: "Date",
|
18
|
-
renderer: (data) => data.value.toLocaleDateString(undefined, {weekday: "long", year: "numeric", month: "long", day: "numeric"}),
|
19
|
-
}, {
|
20
|
-
dataField: "humanReadableLocation",
|
21
|
-
text: "Location",
|
22
|
-
}, {
|
23
|
-
dataField: "size",
|
24
|
-
text: "Magnitude",
|
25
|
-
align: "right",
|
26
|
-
renderer: (data) => data.value.toLocaleString(),
|
27
|
-
}],
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
Neo.setupClass(Table);
|
32
|
-
|
33
|
-
export default Table;
|
34
|
-
</pre>
|
35
|
-
|
36
|
-
</details>
|
37
|
-
|
38
|
-
<details>
|
39
|
-
<summary>Review the code</summary>
|
40
|
-
|
41
|
-
- The class extends `Neo.table.Container`
|
42
|
-
- It has an `ntype`, which we can use when creating an instance, or when debugging
|
43
|
-
- Each column has `text` and `dataField` configs, and some have renderers
|
44
|
-
|
45
|
-
</details>
|
46
|
-
|
47
|
-
<details>
|
48
|
-
<summary>Use the new component</summary>
|
49
|
-
|
50
|
-
Edit `apps/earthquakes/view/MainView` and make these changes.
|
51
|
-
|
52
|
-
- Add `import EarthquakesTable from './earthquakes/Table.mjs';`
|
53
|
-
- Replace the `module: Table` with `module: EarthquakesTable`
|
54
|
-
- Remove the `columns:[]` config
|
55
|
-
- Leave the `store` config alone
|
56
|
-
|
57
|
-
Save and refresh the browser, and your app should run as before.
|
58
|
-
|
59
|
-
You can confim that the new class _is being loaded_ by using DevTools to try to open `earthquakes/Table` — if it
|
60
|
-
was imported, it'll be listed.
|
61
|
-
|
62
|
-
You can confirm that an instance _was created_ by using the DevTools console and searching for it via
|
63
|
-
|
64
|
-
Neo.first('earthquakes-table')
|
65
|
-
|
66
|
-
</details>
|
67
|
-
|
68
|
-
<details>
|
69
|
-
<summary>Here's the code</summary>
|
70
|
-
|
71
|
-
<pre data-javascript>
|
72
|
-
import Base from '../../../node_modules/neo.mjs/src/container/Base.mjs';
|
73
|
-
import Controller from './MainViewController.mjs';
|
74
|
-
import EarthquakesTable from './earthquakes/Table.mjs';
|
75
|
-
import Store from '../../../node_modules/neo.mjs/src/data/Store.mjs';
|
76
|
-
import ViewModel from './MainViewModel.mjs';
|
77
|
-
|
78
|
-
class MainView extends Base {
|
79
|
-
static config = {
|
80
|
-
className: 'Earthquakes.view.MainView',
|
81
|
-
ntype: 'earthquakes-main',
|
82
|
-
|
83
|
-
controller: {module: Controller},
|
84
|
-
model: {module: ViewModel},
|
85
|
-
|
86
|
-
layout: {ntype: 'vbox', align: 'stretch'},
|
87
|
-
items: [{
|
88
|
-
module: EarthquakesTable,
|
89
|
-
store: {
|
90
|
-
module: Store,
|
91
|
-
model: {
|
92
|
-
fields: [{
|
93
|
-
name: "humanReadableLocation",
|
94
|
-
}, {
|
95
|
-
name: "size",
|
96
|
-
}, {
|
97
|
-
name: "timestamp",
|
98
|
-
type: "Date",
|
99
|
-
}],
|
100
|
-
},
|
101
|
-
url: "https://apis.is/earthquake/is",
|
102
|
-
responseRoot: "results",
|
103
|
-
autoLoad: true,
|
104
|
-
},
|
105
|
-
style: {width: '100%'},
|
106
|
-
}],
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
Neo.setupClass(MainView);
|
111
|
-
|
112
|
-
export default MainView;
|
113
|
-
</pre>
|
114
|
-
|
115
|
-
</details>
|
116
|
-
|
117
|
-
<details>
|
118
|
-
<summary>Why are some things in `MainView` and not in `Table`?</summary>
|
119
|
-
|
120
|
-
When we refactored the table into its own class we didn't move all the configs. Both
|
121
|
-
the width styling and `store` were left in `MainView`. Why?
|
122
|
-
|
123
|
-
It's a matter of re-use and what you need in a given situation. By leaving the width specification
|
124
|
-
outside the table class we're free to specify a different value the various places we might be using the table.
|
125
|
-
|
126
|
-
Similarly, if the store were in the table class, it would be using that specific store and
|
127
|
-
each instance of the table would have its own instance of the store. If we want multiple
|
128
|
-
instance of the table with each using a different store — or if
|
129
|
-
we wanted to share the store with other components — then it makes sense for the
|
130
|
-
store to be outside the table class.
|
131
|
-
|
132
|
-
</details>
|
133
|
-
|
134
|
-
<details>
|
135
|
-
<summary>Make a second instance of the table</summary>
|
136
|
-
|
137
|
-
To further illustrate that the table is reusable, let's create a second instance.
|
138
|
-
|
139
|
-
Simply copy-and-paste the value in the `MainView` `items` with an identical second item.
|
140
|
-
|
141
|
-
Save and refresh and you should see two tables.
|
142
|
-
|
143
|
-
<img style="width:80%" src="https://s3.amazonaws.com/mjs.neo.learning.images/earthquakes/EarthquakesTwoTables.png"></img>
|
144
|
-
|
145
|
-
</details>
|
146
|
-
|