-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
335 lines (271 loc) · 10.6 KB
/
index.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Beautifulproperties.js by monjudoh</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
</head>
<body>
<section class="page-header">
<h1 class="project-name">Beautifulproperties.js</h1>
<h2 class="project-tagline"></h2>
<a href="https://github.com/monjudoh/BeautifulProperties.js" class="btn">View on GitHub</a>
<a href="https://github.com/monjudoh/BeautifulProperties.js/zipball/master" class="btn">Download .zip</a>
<a href="https://github.com/monjudoh/BeautifulProperties.js/tarball/master" class="btn">Download .tar.gz</a>
</section>
<section class="main-content">
<h1>
<a id="beautifulpropertiesjs---extension-of-ecmascript5-property" class="anchor" href="#beautifulpropertiesjs---extension-of-ecmascript5-property" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>BeautifulProperties.js - Extension of ECMAScript5 property.</h1>
<h1>
<a id="links" class="anchor" href="#links" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Links</h1>
<ul>
<li> <a href="https://github.com/monjudoh/BeautifulProperties.js">Repository</a>
</li>
<li> <a href="http://monjudoh.github.io/BeautifulProperties.js/docs/index.html">Reference</a>
</li>
</ul>
<h1>
<a id="features" class="anchor" href="#features" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Features</h1>
<h2>
<a id="lazyinitializable" class="anchor" href="#lazyinitializable" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>LazyInitializable</h2>
<p>BeautifulProperties.LazyInitializable.define can define a property, it's
initialized at first access.</p>
<pre lang="sourceCode"><code>var proto = {};
BeautifulProperties.LazyInitializable.define(proto,'boundFunction',function(){
return (function () {
console.log(this);
}).bind(this);
});
var object1 = Object.create(proto);
object1.a = 1;
var boundFunction1 = object1.boundFunction;
boundFunction1();// {a:1,boundFunction:fn}
var object2 = Object.create(proto);
object2.a = 2;
var boundFunction2 = object2.boundFunction;
boundFunction2();// {a:2boundFunction:fn}
</code></pre>
<h2>
<a id="hookable" class="anchor" href="#hookable" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Hookable</h2>
<p>BeautifulProperties.Hookable.define supports hooks for setting/getting
property,replace or modify value.</p>
<p>hooks</p>
<pre lang="sourceCode"><code>var object = {};
BeautifulProperties.Hookable.define(object,'key');
BeautifulProperties.Hookable.addHook(object,'key','beforeInit',function(val){
console.log('beforeInit',val);
return val;
});
BeautifulProperties.Hookable.addHook(object,'key','afterInit',function(val){
console.log('afterInit',val);
});
BeautifulProperties.Hookable.addHook(object,'key','beforeGet',function(){
console.log('beforeGet');
});
BeautifulProperties.Hookable.addHook(object,'key','afterGet',function(val){
console.log('afterGet',val);
return val;
});
BeautifulProperties.Hookable.addHook(object,'key','beforeSet',function(val,previousVal){
console.log('beforeSet',val,previousVal);
return val;
});
BeautifulProperties.Hookable.addHook(object,'key','afterSet',function(val,previousVal){
console.log('afterSet',val,previousVal);
});
object.key = 1;
object.key = 2;
object.key;
</code></pre>
<p>modify getting value</p>
<pre lang="sourceCode"><code>var object = {};
BeautifulProperties.Hookable.define(object,'key');
BeautifulProperties.Hookable.addHook(object,'key','afterGet',function(val){
return val * 2;
});
object.key = 1;
object.key;//2
</code></pre>
<p>modify setting value</p>
<pre lang="sourceCode"><code>var object = {};
BeautifulProperties.Hookable.define(object,'key');
BeautifulProperties.Hookable.addHook(object,'key','beforeInit',function(val,previousVal){
return val * 2;
});
BeautifulProperties.Hookable.addHook(object,'key','beforeSet',function(val,previousVal){
return val * 3;
});
object.key = 1;
object.key;//2
object.key = 1;
object.key;//3
</code></pre>
<h2>
<a id="events" class="anchor" href="#events" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Events</h2>
<pre lang="sourceCode"><code>var object = {};
BeautifulProperties.Events.on(object,'eventType',function(ev){
console.log('event handler is called.');
});
BeautifulProperties.Events.trigger(object,'eventType');
</code></pre>
<p>event bubbling.</p>
<p>A event bubble up to the prototype of the object.</p>
<pre lang="sourceCode"><code>var proto = {};
var object = Object.create(proto);
BeautifulProperties.Events.on(proto,'eventType',function(ev){
console.log('event handler is called.');
});
BeautifulProperties.Events.trigger(object,'eventType');
</code></pre>
<p>controlling event bubbling.</p>
<pre lang="sourceCode"><code>var ancestor = {};
var object = {};
BeautifulProperties.Events.Ancestor.setRetriever(object,function(){
return ancestor;
});
BeautifulProperties.Events.on(ancestor,'eventType',function(ev){
console.log('event handler is called.');
});
BeautifulProperties.Events.trigger(object,'eventType');
</code></pre>
<h2>
<a id="observable" class="anchor" href="#observable" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Observable</h2>
<p>BeautifulProperties.Observable.define supports key/value observation.</p>
<pre lang="sourceCode"><code>var object = {};
BeautifulProperties.Observable.define(object,'key');
BeautifulProperties.Events.on(object,'init:key',function(ev,val){
console.log(val);// val:1
});
BeautifulProperties.Events.on(object,'change:key',function(ev,val,previousVal){
console.log(val,previousVal);// val:2,previousVal:1
});
object.key=1;
object.key=2;
</code></pre>
<h1>
<a id="installation-and-usage" class="anchor" href="#installation-and-usage" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Installation and usage</h1>
<h2>
<a id="in-browsers" class="anchor" href="#in-browsers" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>In browsers:</h2>
<pre lang="sourceCode"><code><script src="BeautifulProperties.js"></script>
</code></pre>
<h2>
<a id="in-an-amd-loader-like-requirejs" class="anchor" href="#in-an-amd-loader-like-requirejs" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>In an AMD loader like RequireJS:</h2>
<pre lang="sourceCode"><code>require(['BeautifulProperties'], function(BeautifulProperties) {
});
</code></pre>
<h1>
<a id="changelog" class="anchor" href="#changelog" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Changelog</h1>
<h2>
<a id="020" class="anchor" href="#020" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>0.2.0</h2>
<ul>
<li> changed
<ul>
<li>It trigger init:{key} event when Observable property is
initialized.</li>
</ul>
</li>
<li> removed
<ul>
<li> BeautifulProperties.Hookable.addHooks method</li>
<li> BeautifulProperties.Internal namespace</li>
<li> context property of BeautifulProperties.Events~BindingOptions</li>
</ul>
</li>
</ul>
<h2>
<a id="0112" class="anchor" href="#0112" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>0.1.12</h2>
<ul>
<li> added
<ul>
<li>Multiple binding is supported in BeautifulProperties.Events.</li>
</ul>
</li>
<li> changed
<ul>
<li>context property of BeautifulProperties.Events~BindingOptions is
renamed to thisObject.</li>
</ul>
</li>
<li> deprecated
<ul>
<li> context property of BeautifulProperties.Events~BindingOptions</li>
</ul>
</li>
</ul>
<h2>
<a id="0111" class="anchor" href="#0111" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>0.1.11</h2>
<ul>
<li> fixes
<ul>
<li> event.previousTarget,event.currentTarget in
BeautifulProperties.Events.Ancestor~ancestorRetriever.</li>
</ul>
</li>
</ul>
<h2>
<a id="0110" class="anchor" href="#0110" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>0.1.10</h2>
<ul>
<li> added
<ul>
<li>BeautifulProperties.Events.Event#previousTarget property</li>
</ul>
</li>
<li> changed
<ul>
<li> BeautifulProperties.Events.Ancestor~ancestorRetriever callback
<ul>
<li> has 2 params.</li>
<li> If the ancestorRetriever returns undefined,Ancestor.retrieve
method returns the prototype of the target object.</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2>
<a id="019" class="anchor" href="#019" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>0.1.9</h2>
<ul>
<li> Export as global,AMD,CJS.</li>
<li> Many refacotoring.</li>
<li>
<p>deprecated</p>
<ul>
<li><p>BeautifulProperties.Hookable.addHooks method</p></li>
<li><p>BeautifulProperties.Internal namespace is deprecated.</p></li>
</ul>
</li>
<li> removed
<ul>
<li> BeautifulProperties.getRaw method (deprecated since 0.1.6)</li>
<li> BeautifulProperties.setRaw method (deprecated since 0.1.6)</li>
</ul>
</li>
</ul>
<h1>
<a id="author" class="anchor" href="#author" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Author</h1>
<p>monjudoh <a href="https://github.com/monjudoh">https://github.com/monjudoh</a></p>
<h1>
<a id="contributors" class="anchor" href="#contributors" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Contributors</h1>
<ul>
<li> aodag (Atsushi Odagiri) <a href="https://github.com/aodag">https://github.com/aodag</a>
<ul>
<li>He named this library.</li>
</ul>
</li>
<li> jbking (Yusuke Muraoka) <a href="https://github.com/jbking">https://github.com/jbking</a>
<ul>
<li> He provides ideas for this library.</li>
</ul>
</li>
</ul>
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://github.com/monjudoh/BeautifulProperties.js">Beautifulproperties.js</a> is maintained by <a href="https://github.com/monjudoh">monjudoh</a>.</span>
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
</footer>
</section>
</body>
</html>