Skip to content

Commit

Permalink
- updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
canonic-epicure committed Apr 29, 2010
1 parent cd9aa13 commit eb916c3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 28 deletions.
27 changes: 25 additions & 2 deletions lib/Joose/Manual/Classes.js
Expand Up @@ -37,10 +37,10 @@ These builders are what you use to define your class. For example, you might def
Attributes are described in the [Joose.Manual.Attributes][2] documentation.
When you use Joose, your class will become a subclass of `Joose.Meta.Object`. The `Joose.Meta.Object` class provides a default `initialize` method and a number of additional methods.
When you use Joose, your class will become a subclass of `Joose.Meta.Object`. The `Joose.Meta.Object` class provides a default constructor and a number of additional methods.
You can read more about this in the [Joose][3] document.
Joose creates an instance of `Joose.Meta.Class` for your class. This metaclass instance is now available as a meta property on your class, for example: `Person.meta`
Joose creates an instance of `Joose.Meta.Class` for your class. This metaclass instance is now available as a `meta` property on your class, for example: `Person.meta`
The metaclass object provides an introspection API for your class. It is also used by Joose itself under the hood to add attributes, compose roles, and so on.
In fact, all of Joose's sugar does the real work by calling methods on this metaclass object (and other meta API objects).
Expand All @@ -53,6 +53,28 @@ In case your global scope already contains `Class` symbol, you can use the `Joos
There are also corresponding `Joose.Role` and `Joose.Module` aliases.
VERSION & AUTHORITY
===================
Each class supports the `VERSION` and `AUTHORITY` builders:
Class('Person', {
VERSION : 0.01,
AUTHORITY : 'jsan:SomeCleverGuy',
...
})
Version is self-explanatory, and "authority" is an URI identifying the author (or another authorizing authority). This information is availbale in corresponding properties
of `meta` instance:
Person.meta.VERSION
Person.meta.AUTHORITY
Among other use-cases, this information is used by the dependencies loader `JooseX.Namespace.Depended`, which is provided in separate distribution, see [JooseX]
ANONYMOUS CLASSES
=================
Expand Down Expand Up @@ -127,5 +149,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
[2]: Attributes.html
[3]: Construction.html
[4]: Roles.html
[JooseX]: JooseX.html
*/
68 changes: 43 additions & 25 deletions lib/Joose/Manual/Construction.js
Expand Up @@ -138,10 +138,49 @@ You don't need to manually pre-create the namespace for your class - just go ahe
Note, how `MyApp` class was created already *after* its namespace segment was declared. This is a perfectly valid declaration.
`body` BUILDER
==============
NESTING NAMESPACES
==================
Each class also support special builder `body`, which should be a function. This function will be called right after class construction, with the class's constructor as 1st argument and in the same scope.
You may declare new classes (or roles) in the `body`. Such class's constructor will be placed in the namespace of the outer class. If you need to declare the class in the global namespace from `body`, then
prefix its name with dot:
Class("MyApp.Point", {
body : function (myAppPoint) {
console.log(myAppPoint == MyApp.Point) //prints 'true'
console.log(this == MyApp.Point) //prints 'true'
...
// nested class
Class("ThreeD", {
isa: MyApp.Point,
has: {
z: {}
}
}
// class in global namespace
Class(".MyApp.Circle", {
has: {
radius: {}
}
}
}
})
var point = new MyApp.Point()
var point3d = new MyApp.Point.ThreeD()
var circle = new MyApp.Circle()
The class will be already fully constructed at the time of `body` execution, you can create its instances or even *extend* it with some additional
methods (see [Joose.Manual.Mutability][1] for details)
Each class also support special builder `body`, which should be a function.
Class("MyApp.Point.ThreeD", {
isa: Point,
Expand Down Expand Up @@ -169,32 +208,11 @@ Each class also support special builder `body`, which should be a function.
}
})
**NOTE:** `body` builder is a correct place to perform some action after creation of class, because in general case, the creation may be asynchronous (for dependency loading for example).
This function will be called right after class construction, with the class's constructor as 1st argument and in the same scope.
The class will be already fully constructed at the time of `body` execution, you can create its instances or even *extend* it with some additional
methods (see [Joose.Manual.Mutability][1] for details)
You may declare new classes (or roles) in the `body`. Such class's constructor will be placed in the namespace of the outer class.
Class("MyApp.Point", {
body : function () {
Class("ThreeD", {
isa: MyApp.Point,
has: {
z: {}
}
}
}
})
var point = new MyApp.Point()
var point3d = new MyApp.Point.ThreeD()
**NOTE:** `body` builder is a correct place to perform some action after creation of class, because in general case, the creation may be asynchronous (for dependency loading for example).
MODULES
Expand Down
2 changes: 2 additions & 0 deletions lib/Joose/Manual/JooseX.js
Expand Up @@ -61,6 +61,8 @@ This is very flexible implementation of dependency handling system for Joose cla
It integrates directly into class creation process, and supports versioning:
Class('User', {
VERSION : 1.23,
isa : {
Person : 1.15
},
Expand Down
9 changes: 8 additions & 1 deletion t/060_modules.t.js
@@ -1,5 +1,5 @@
StartTest(function (t) {
t.plan(60)
t.plan(62)

//==================================================================================================================================================================================
t.diag("Modules")
Expand All @@ -15,6 +15,10 @@ StartTest(function (t) {
t.ok(globalNs.container == Joose.top, "Container of global namespace is a top scope")

Module('TestModule', {

VERSION : 0.01,
AUTHORITY : 'auth',

body : function (module) {
this.foo = 'bar'
module.bar = 'baz'
Expand All @@ -24,6 +28,9 @@ StartTest(function (t) {
t.ok(TestModule, 'Something in the module spot appears')
t.ok(TestModule.meta.constructor == Joose.Namespace.Keeper, '.. and its a Joose.Namespace.Keeper')

t.ok(TestModule.meta.VERSION == 0.01, 'Correct VERSION detected')
t.ok(TestModule.meta.AUTHORITY == 'auth', 'Correct AUTHORITY detected')

t.ok(TestModule.meta.ns.container == TestModule, 'Container of namespace is a module function')
t.is(TestModule.foo, 'bar', 'Body of module was executed in the scope of its container')
t.is(TestModule.bar, 'baz', 'Module namespacekeeper was also passed as 1st argument to body')
Expand Down

0 comments on commit eb916c3

Please sign in to comment.