-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathngDemoScript.txt
126 lines (91 loc) · 3.37 KB
/
ngDemoScript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
ngDemoScript
============
NEW FILES
index.html: (ngicreate)
app: (ngacreate)
datacontext (ngdcreate)
----------------------
Controller should get something when it starts
app: add getItems (ngaget)
-----------------
Give the DataContext a different dummy get
datacontext: replace getItems (ngdget)
------------------
Bind to it (ngibind)
index: {{item.FirstName}} {{item.LastName}}
-----------------
Give the DataContext an $http version
datacontext: (ngd$http) // replace getSucceeded as well
[set datasource switch in app.js to local/remote as needed]
-----------------
"What about the order? filtering?"
Switch to simple Breeze query
datacontext (ngdspeakers) // replace promise and getSucceeded as well
-----
Will load but won't display until change to camelCase
index: {{item.firstName}} {{item.lastName}} // <-- camelCase !!!
datacontext: add to query: .orderBy('firstName, lastName')
datacontext: add to query: .where('lastName', 'startsWith', 'B') (or 'b')
-----------------
"Too much data in a Speaker? Use a projection"
datacontext: add to query: .select('firstName, lastName')
SHOW network traffic
REMOVE it (will interfere with later stuff;
-----------------
"Don't hardcode 'b'; let's make a searchBox "
index: add below <h1> (ngisearch)
"use it in the controller"
app: add (ngasearch)
$scope.searchText = "";
$scope.$watch('searchText', getItems);
"make the datacontext use it"
datacontext: getItems
ADD 'searchText' PARAMETER
insert search in getItems (ngdsearch)
-----------------
"Why search just the last name? Let's search first name too"
datacontext: replace "query = query.where(..." with (ngdpred)
-----------------
"What if network is slow ... let's make it slow"
datacontext: replace "return manager.execute..." (ngdslow)
-----------------
"Let's wait until user stops typing"
app: add delayedSearch (ngadelay) ... just above getItems()
replace watch fn with delayedSearch
-----------------
"Why go to the server when we have all the speakers anyway?
We can query locally"
index: above search (ngistaylocal)
app: bottom of $scope (ngastaylocal)
dc: replace "if (searchText) ..." block (ngdstaylocal)
-----------------
"What about related info? Speakers have sessions"
"Can fetch eagerly or on demand ... let's do eagerly"
dc: in getItems query add .expand('speakerSessions')
index: change display of lists (ngiexpand)
-----------------
"Model entities have behavior. Where are they?"
ADD new model.js (ngmCreate)
dc: get model and initialize it
add 'model' to ctor
after manager def, call model.initialize(manager.metadataStore);
index:
add <script src="model.js"></script>
show fullname (ngifullname)
----------------------------------------
CHANGE TRACKING & VALIDATION
isDirty ... in the entity, not the screen
changing what's displayed doesn't change entity-is-dirty
Breakpoint in datacontext on local (just to stop it)
At the break:
manager.getChanges()
manager.getChanges()[0].fullName()
manager.getChanges()[0].entityAspect.entityState
manager.getChanges()[0].entityAspect.originalValues
manager.getChanges()[0].entityAspect.getValidationErrors()
Rollback
manager.rejectChanges()
------------------------------------
METADATA
// explore the type; find the validators on the "firstName" property
manager.metadataStore.getEntityType('Person')