Skip to content

Commit fc7bcc3

Browse files
@mixin: filled out doc
1 parent 4e8eb4e commit fc7bcc3

File tree

3 files changed

+154
-11
lines changed

3 files changed

+154
-11
lines changed

Jake/articles/tags-mixin

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,93 @@
11
<!--{
22
"title": "@mixin",
33
"out": "tags-mixin.html",
4-
"description": "[todo] Document a mix-in object."
4+
"description": "Document a mix-in object."
55
}-->
6+
7+
<h3>Syntax</h3>
8+
<code>@mixin [&lt;MixinName&gt;]</code>
9+
610
<h3>Overview</h3>
711

812
<p>
13+
A mixin is a class providing functionality that is intended to be added in to other classes desiring that functionality.
14+
The @mixin tag allows the user to mark an object as a mixin.
15+
</p>
16+
17+
<p>
18+
For example, you might have an "Eventful" mixin which provides event handling methods to other classes, but isn't intended to be used itself.
919
</p>
1020

1121
<h3>Examples</h3>
1222

23+
{{#example}}Example of a @mixin
24+
/**
25+
* This provides methods used for event handling. It's not meant to
26+
* be used directly, except as a provider of related methods.
27+
*
28+
* @mixin
29+
*/
30+
var Eventful = {
31+
/** Register a handler function to be called whenever this event is fired.
32+
* @param {string} eventName - name of the event
33+
* @param {Eventful~eventHandler} handler - the handler to be called.
34+
*/
35+
on: function(eventName, handler) {
36+
// code...
37+
},
38+
39+
/** Fires an event, causing all handlers for that event name to run.
40+
* @param {string} eventName - name of the event
41+
* @param {object} eventData - passed into each handler.
42+
*/
43+
fire: function(eventName, eventData) {
44+
// code...
45+
}
46+
};
47+
/** Used as an event callback {@link Eventful.on}.
48+
* @callback Eventful~eventHandler
49+
* @param {object} eventData - the event data.
50+
*/
51+
{{/example}}
52+
1353
<p>
54+
In the above we document a set of methods, Eventful, that can be mixed in to other classes to give them the ability to fire and listen to events.
55+
(Note also the use of the <a href="tags-callback.html">@callback</a> tag to document the event handler parameter in the "on" function - we could have just written "@param {function(object)} handler" instead if we didn't want to use that).
1456
</p>
1557

16-
{{#example}}Example goes here
17-
// todo
58+
<p>
59+
Use <a href="tags-mixes.html">@mixes</a> to indicate in the documentation that another class mixes in Eventful (you are still responsible for doing the actual mixing in the code, however). Note, this doesn't support references like "{@link FormButton#on}" (yet).
60+
</p>
61+
62+
{{#example}}Having another class @mixes Eventful
63+
/**
64+
* @constructor FormButton
65+
* @mixes Eventful
66+
*/
67+
var FormButton = function() {
68+
// code...
69+
};
70+
FormButton.prototype.press = function() {
71+
this.fire('press', {});
72+
}
73+
mix(Eventful).into(FormButton.prototype);
74+
75+
function mix(source) {
76+
return {into: function(target) {
77+
for (var property in source) {
78+
if( !(property in {}) ) {
79+
target[property] = source[property]
80+
}
81+
}
82+
return this;
83+
}};
84+
}
1885
{{/example}}
1986

2087
<h3>See Also</h3>
2188

2289
<ul>
23-
<li><a href="#">...</a></li>
24-
</ul>
90+
<li><a href="tags-mixes.html">@mixes</a></li>
91+
<li><a href="tags-borrows.html">@borrows</a></li>
92+
<li><a href="tags-constructor.html">@class</a></li>
93+
</ul>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ <h2 name="JSDoc3_Tag_Dictionary" id="JSDoc3_Tag_Dictionary">JSDoc 3 Tag Dictiona
263263
<dd>When was this feature added?</dd> <dt><a href="tags-access.html">@access</a></dt>
264264
<dd>Specify the access level of this member - private, public, or protected.</dd> <dt><a href="tags-borrows.html">@borrows</a></dt>
265265
<dd>This object uses something from another object.</dd> <dt><a href="tags-mixin.html">@mixin</a></dt>
266-
<dd>[todo] Document a mix-in object.</dd> <dt><a href="tags-see.html">@see</a></dt>
266+
<dd>Document a mix-in object.</dd> <dt><a href="tags-see.html">@see</a></dt>
267267
<dd>[todo] Refer to some other documentation for more information.</dd> <dt><a href="tags-file.html">@file</a></dt>
268268
<dd>Describe a file.</dd> <dt><a href="tags-example.html">@example</a></dt>
269269
<dd>Provide an example of how to use a documented item.</dd> <dt><a href="tags-tutorial.html">@tutorial</a></dt>

tags-mixin.html

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<meta name="description" content="[todo] Document a mix-in object."><title>Use JSDoc: @mixin</title>
5+
<meta name="description" content="Document a mix-in object."><title>Use JSDoc: @mixin</title>
66

77
<link rel="stylesheet" href="lib/prettify.css" />
88
<script src="lib/prettify.js"></script>
@@ -176,29 +176,103 @@
176176
<article>
177177
<h1>@mixin</h1>
178178

179+
180+
<h3>Syntax</h3>
181+
<code>@mixin [&lt;MixinName&gt;]</code>
182+
179183
<h3>Overview</h3>
180184

181185
<p>
186+
A mixin is a class providing functionality that is intended to be added in to other classes desiring that functionality.
187+
The @mixin tag allows the user to mark an object as a mixin.
188+
</p>
189+
190+
<p>
191+
For example, you might have an "Eventful" mixin which provides event handling methods to other classes, but isn't intended to be used itself.
182192
</p>
183193

184194
<h3>Examples</h3>
185195

196+
<dl class="example">
197+
<dt>Example of a @mixin</dt>
198+
<dd>
199+
<pre class="prettyprint lang-js">
200+
/**
201+
* This provides methods used for event handling. It's not meant to
202+
* be used directly, except as a provider of related methods.
203+
*
204+
* @mixin
205+
*/
206+
var Eventful = {
207+
/** Register a handler function to be called whenever this event is fired.
208+
* @param {string} eventName - name of the event
209+
* @param {Eventful~eventHandler} handler - the handler to be called.
210+
*/
211+
on: function(eventName, handler) {
212+
// code...
213+
},
214+
215+
/** Fires an event, causing all handlers for that event name to run.
216+
* @param {string} eventName - name of the event
217+
* @param {object} eventData - passed into each handler.
218+
*/
219+
fire: function(eventName, eventData) {
220+
// code...
221+
}
222+
};
223+
/** Used as an event callback {@link Eventful.on}.
224+
* @callback Eventful~eventHandler
225+
* @param {object} eventData - the event data.
226+
*/
227+
228+
</pre>
229+
</dd>
230+
</dl><p>
231+
In the above we document a set of methods, Eventful, that can be mixed in to other classes to give them the ability to fire and listen to events.
232+
(Note also the use of the <a href="tags-callback.html">@callback</a> tag to document the event handler parameter in the "on" function - we could have just written "@param {function(object)} handler" instead if we didn't want to use that).
233+
</p>
234+
186235
<p>
236+
Use <a href="tags-mixes.html">@mixes</a> to indicate in the documentation that another class mixes in Eventful (you are still responsible for doing the actual mixing in the code, however). Note, this doesn't support references like "{@link FormButton#on}" (yet).
187237
</p>
188238

189239
<dl class="example">
190-
<dt>Example goes here</dt>
240+
<dt>Having another class @mixes Eventful</dt>
191241
<dd>
192242
<pre class="prettyprint lang-js">
193-
// todo
243+
/**
244+
* @constructor FormButton
245+
* @mixes Eventful
246+
*/
247+
var FormButton = function() {
248+
// code...
249+
};
250+
FormButton.prototype.press = function() {
251+
this.fire('press', {});
252+
}
253+
mix(Eventful).into(FormButton.prototype);
254+
255+
function mix(source) {
256+
return {into: function(target) {
257+
for (var property in source) {
258+
if( !(property in {}) ) {
259+
target[property] = source[property]
260+
}
261+
}
262+
return this;
263+
}};
264+
}
194265

195266
</pre>
196267
</dd>
197268
</dl><h3>See Also</h3>
198269

199270
<ul>
200-
<li><a href="#">...</a></li>
201-
</ul>
271+
<li><a href="tags-mixes.html">@mixes</a></li>
272+
<li><a href="tags-borrows.html">@borrows</a></li>
273+
<li><a href="tags-constructor.html">@class</a></li>
274+
</ul>
275+
202276
</article>
203277

204278
<footer>

0 commit comments

Comments
 (0)