/
Observable.html
446 lines (444 loc) · 12.1 KB
/
Observable.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>CoffeeScript API Documentation</title>
<link rel='stylesheet' href='../../assets/codo.css' type='text/css'>
<script src='../../assets/codo.js'></script>
<script src='../../assets/search_data.js'></script>
</head>
<body>
<div id='base' data-path='../../'></div>
<div id='header'>
<div id='menu'>
<a href='../../class_index.html' title='Index'>Index</a>
»
<a href='../../classes/kb.html' title='kb'>kb</a>
»
<span class='title'>Observable</span>
<nav>
<ul>
<li class='noframes'>
(<a class='noframes' href='#'>no frames</a>)
</li>
</ul>
</nav>
<div id='search'>
<a id='class_list_link' href='../../class_list.html'>Classes</a>
<a id='method_list_link' href='../../method_list.html'>Methods</a>
<a id='extra_list_link' href='../../extra_list.html'>Extras</a>
</div>
</div>
<iframe id='search_frame'></iframe>
<div id='fuzzySearch'>
<input type='text'>
<ol></ol>
</div>
<div id='help'>
<p>
Quickly fuzzy find classes, mixins, methods, file:
</p>
<ul>
<li>
<span>Ctrl-T</span>
Open fuzzy finder dialog
</li>
</ul>
<p>
In frame mode you can toggle the list naviation frame on the left side:
</p>
<ul>
<li>
<span>Ctrl-L</span>
Toggle list view
</li>
</ul>
<p>
You can focus a list in frame mode or toggle a tab in frameless mode:
</p>
<ul>
<li>
<span>Ctrl-C</span>
Class list
</li>
<li>
<span>Ctrl-I</span>
Mixin list
</li>
<li>
<span>Ctrl-F</span>
File list
</li>
<li>
<span>Ctrl-M</span>
Method list
</li>
<li>
<span>Ctrl-E</span>
Extras list
</li>
</ul>
<p>
You can focus and blur the search input:
</p>
<ul>
<li>
<span>Ctrl-S</span>
Focus search input
</li>
<li>
<span>Esc</span>
Blur search input
</li>
</ul>
<p>
In frameless mode you can close the list tab:
</p>
<ul>
<li>
<span>Esc</span>
Close list tab
</li>
</ul>
</div>
</div>
<div id='content'>
<h1>
Class:
kb.Observable
</h1>
<table class='box'>
<tr>
<td>Defined in:</td>
<td>src/knockback-core/knockback-observable.coffee</td>
</tr>
</table>
<h2>Overview</h2>
<div class='docstring'>
<p>Base class for observing model attributes. </p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
How to create a ko.CollectionObservable using the ko.collectionObservable factory.
</h4>
<pre><code class='coffee'>var ContactViewModel = function(model) {
this.name = kb.observable(model, 'name');
this.number = kb.observable(model, { key: 'number'});
};
var model = new Contact({ name: 'Ringo', number: '555-555-5556' });
var view_model = new ContactViewModel(model);</code></pre>
<h4>
How to create a kb.Observable with a default value.
</h4>
<pre><code class='coffee'>var model = Backbone.Model({name: 'Bob'});
var name = kb.observable(model, {key:'name', default: '(none)'}); // name is Bob
name.setToDefault(); // name is (none)</code></pre>
</div>
</div>
<div class='tags'>
</div>
<h2>Instance Method Summary</h2>
<ul class='summary'>
<li>
<span class='signature'>
<a href='#constructor-instance'>
- (ko.observable) <strong>constructor</strong>(model, options, vm)
</a>
</span>
<span class='constructor note title'>Constructor</span>
<span class='desc'>
Used to create a new kb.Observable.
</span>
</li>
<li>
<span class='signature'>
<a href='#destroy-instance'>
- (void) <strong>destroy</strong>()
</a>
</span>
<span class='desc'>
Required clean up function to break cycles, release view models, etc.
</span>
</li>
<li>
<span class='signature'>
<a href='#value-instance'>
- (kb.CollectionObservable|kb.ViewModel|ko.observable) <strong>value</strong>()
</a>
</span>
<span class='desc'>
</span>
</li>
<li>
<span class='signature'>
<a href='#valueType-instance'>
- (kb.TYPE_UNKNOWN|kb.TYPE_SIMPLE|kb.TYPE_ARRAY|kb.TYPE_MODEL|kb.TYPE_COLLECTION) <strong>valueType</strong>()
</a>
</span>
<span class='desc'>
</span>
</li>
<li>
<span class='signature'>
<a href='#model-instance'>
- (void) <strong>model</strong>(new_model)
</a>
</span>
<span class='desc'>
Dual-purpose getter/setter for the observed model.
</span>
</li>
</ul>
<h2>Constructor Details</h2>
<div class='methods'>
<div class='method_details'>
<p class='signature' id='constructor-instance'>
- (ko.observable) <strong>constructor</strong>(model, options, vm)
</p>
<div class='docstring'>
<div class='note'>
<strong>Note:</strong>
the constructor does not return 'this' but a ko.observable
</div>
<p>Used to create a new kb.Observable. </p>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>model</span>
<span class='type'>
(<tt>Backbone.Model</tt>)
</span>
—
<span class='desc'>the model to observe (can be null)</span>
</li>
<li>
<span class='name'>options</span>
<span class='type'>
(<tt>String|Array|Object</tt>)
</span>
—
<span class='desc'>the create options. String is a single attribute name, Array is an array of attribute names.</span>
</li>
</ul>
<h3>
Options Hash:
(options):
</h3>
<ul class='options'>
<li>
<span class='name'>key</span>
<span class='type'>
(<tt>String</tt>)
</span>
—
<span class='desc'>the name of the attribute.</span>
</li>
<li>
<span class='name'>read</span>
<span class='type'>
(<tt>Function</tt>)
</span>
—
<span class='desc'>a function used to provide transform the attribute value before passing it to the caller. Signature: read()</span>
</li>
<li>
<span class='name'>write</span>
<span class='type'>
(<tt>Function</tt>)
</span>
—
<span class='desc'>a function used to provide transform the value before passing it to the model set function. Signature: write(value)</span>
</li>
<li>
<span class='name'>args</span>
<span class='type'>
(<tt>Array</tt>)
</span>
—
<span class='desc'>arguments to pass to the read and write functions (they can be ko.observables). Can be useful for passing arguments to a locale manager.</span>
</li>
<li>
<span class='name'>localizer</span>
<span class='type'>
(<tt>Constructor</tt>)
</span>
—
<span class='desc'>a concrete kb.LocalizedObservable constructor for localization.</span>
</li>
<li>
<span class='name'>default</span>
<span class='type'>
(<tt>Data|ko.observable</tt>)
</span>
—
<span class='desc'>the default value. Can be a value, string or ko.observable.</span>
</li>
<li>
<span class='name'>path</span>
<span class='type'>
(<tt>String</tt>)
</span>
—
<span class='desc'>the path to the value (used to create related observables from the factory).</span>
</li>
<li>
<span class='name'>store</span>
<span class='type'>
(<tt><a href='../../classes/kb/Store.html'>kb.Store</a></tt>)
</span>
—
<span class='desc'>a store used to cache and share view models.</span>
</li>
<li>
<span class='name'>factory</span>
<span class='type'>
(<tt><a href='../../classes/kb/Factory.html'>kb.Factory</a></tt>)
</span>
—
<span class='desc'>a factory used to create view models.</span>
</li>
<li>
<span class='name'>options</span>
<span class='type'>
(<tt>Object</tt>)
</span>
—
<span class='desc'>a set of options merge into these options using _.defaults. Useful for extending options when deriving classes rather than merging them by hand.</span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>ko.observable</tt>)
</span>
—
<span class='desc'>the constructor does not return 'this' but a ko.observable</span>
</li>
</ul>
</div>
</div>
</div>
<h2>Instance Method Details</h2>
<div class='methods'>
<div class='method_details'>
<p class='signature' id='destroy-instance'>
- (void) <strong>destroy</strong>()
</p>
<div class='docstring'>
<p>Required clean up function to break cycles, release view models, etc. Can be called directly, via kb.release(object) or as a consequence of ko.releaseNode(element). </p>
</div>
<div class='tags'>
</div>
</div>
<div class='method_details'>
<p class='signature' id='value-instance'>
- (kb.CollectionObservable|kb.ViewModel|ko.observable) <strong>value</strong>()
</p>
<div class='tags'>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>kb.CollectionObservable|kb.ViewModel|ko.observable</tt>)
</span>
—
<span class='desc'>exposes the raw value inside the kb.observable. For example, if your attribute is a Backbone.Collection, it will hold a kb.CollectionObservable.</span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='valueType-instance'>
- (kb.TYPE_UNKNOWN|kb.TYPE_SIMPLE|kb.TYPE_ARRAY|kb.TYPE_MODEL|kb.TYPE_COLLECTION) <strong>valueType</strong>()
</p>
<div class='tags'>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>kb.TYPE_UNKNOWN|kb.TYPE_SIMPLE|kb.TYPE_ARRAY|kb.TYPE_MODEL|kb.TYPE_COLLECTION</tt>)
</span>
—
<span class='desc'>provides the type of the wrapped value.</span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='model-instance'>
- (Backbone.Model|Backbone.ModelRef) <strong>model</strong>()
<br>
- (void) <strong>model</strong>(new_model)
<br>
</p>
<div class='docstring'>
<p>Dual-purpose getter/setter for the observed model. </p>
</div>
<div class='tags'>
<div class='overloads'>
<h3>Overloads:</h3>
<div class='overload'>
<p class='signature'>
- (Backbone.Model|Backbone.ModelRef) <strong>model</strong>()
</p>
<div class='docstring'>
<p>Gets the model or model reference</p>
</div>
<div class='tags'>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>Backbone.Model|Backbone.ModelRef</tt>)
</span>
—
<span class='desc'>the model whose attribute by key is being observed (can be null)</span>
</li>
</ul>
</div>
</div>
<div class='overload'>
<p class='signature'>
- (void) <strong>model</strong>(new_model)
</p>
<div class='docstring'>
<p>Sets the model or model reference </p>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>new_model</span>
<span class='type'>
(<tt>Backbone.Model|Backbone.ModelRef</tt>)
</span>
—
<span class='desc'>the model whose attribute by key will be observed (can be null)</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id='footer'>
Generated on
Fri Sep 07 2012 22:57:31 GMT+0900 (JST)
by
<a href='https://github.com/netzpirat/codo' title='CoffeeScript API documentation generator'>Codo</a>
v1.3.1
(Node.js v0.8.7).
✲
Press Ctrl-h to see the keyboard shortcuts
✲
<a href='http://twitter.com/#!/netzpirat'>@netzpirat</a>
✲
<a href='https://mksoft.ch'>mksoft.ch</a>
</div>
</body>
</html>