joose and Node

65 views
Skip to first unread message

Hans Stockem

unread,
Mar 16, 2011, 2:27:42 PM3/16/11
to joos...@googlegroups.com
Hi,

I am trying to start using joose3 with nodejs, but only basic things I
can do with it.

For instance: SUBCLASSING NON-JOOSE CLASSES example:
http://joose.github.com/Joose/doc/html/Joose/Manual/Classes.html

require('joose') // or even require('task-joose-nodejs') does not
populate Joose.Meta.Class.

Another thing I really need is Custom Metaclass for Attributes. How do
I implement let's say, JooseX.Attribute.Hashed?
http://joose.github.com/Joose/doc/html/Joose/Manual/Attributes.html

Is there any working usable example of advanced joose for node (0.4.2)?
How to *require* things to make it work?

Thanks you in advance!

Nickolay Platonov

unread,
Mar 16, 2011, 2:35:20 PM3/16/11
to joos...@googlegroups.com
Hi,

I haven't yet tested Joose with node 0.4.x, perhaps they've changed the way "global" works..

Let me try..

Nickolay



--
You received this message because you are subscribed to the Google Groups "Joose" group.
To post to this group, send email to joos...@googlegroups.com.
To unsubscribe from this group, send email to joose-js+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joose-js?hl=en.


Nickolay Platonov

unread,
Mar 16, 2011, 3:06:33 PM3/16/11
to joos...@googlegroups.com
"Subclassing non-Joose classes" example works for me with Node 0.4.2.

Are you testing with node-repl? Somehow node-repl still uses different global scope for evaluation (which will not contain "Joose" after `require('joose')`).
Try to launch it from the separate file.

About the custom metaclass for attributes - please refer to this thread: http://groups.google.com/group/joose-js/browse_thread/thread/fa723116002527c1#

Currently there's not much documentation for meta-layer, so if you'll have any questions - ask here or you are welcome to #joose on freenode.

Regards, Nickolay

Hans Stockem

unread,
Mar 16, 2011, 4:12:32 PM3/16/11
to joos...@googlegroups.com
Hi Nickolay,

my problem cause is the Node CLI.
If I wrap a code into a module - SUBCLASSING NON-JOOSE CLASSES example
works fine.

http://dpaste.com/507924/

Here is what I get via CLI:

> require('joose')
{ Class: [Function], Role: [Function], Module: [Function] }


> var J = require('joose')
> console.dir(J)
{ Class: [Function], Role: [Function], Module: [Function] }


Sorry for the mess. I should not trust CLI too much. :)

Joose looks very useful for my projects. Thank you!


2011/3/16 Nickolay Platonov <nick...@gmail.com>:

Nickolay Platonov

unread,
Mar 16, 2011, 4:45:30 PM3/16/11
to joos...@googlegroups.com
Aha, its a known issue. Joose aims to be cross-platform and works in browsers as well, so it modifies the global scope (adds "Joose" to it).
Somehow node-repl can't pick it up.

Michael Bradley, Jr.

unread,
May 31, 2011, 4:01:33 PM5/31/11
to joos...@googlegroups.com
I've been using a handy little script to preload the node.js REPL with 'task-joose-nodejs', and today I decided to stick it out on GitHub:


There's nothing to it, really, but I find it a convenient thing to clone to VMs I'm working in instead of re-creating it by hand when I need it.

I tend to a keep REPL running in a terminal on my dekstop at all times when I'm coding JavaScript -- I often find it more convenient for doing quick tests and sanity checks than firing up the console in a browser or setting up a test script.

Nickolay Platonov

unread,
Jun 1, 2011, 2:59:47 AM6/1/11
to joos...@googlegroups.com
Great finding!

--

Adam Bergmark

unread,
Jun 1, 2011, 7:57:24 AM6/1/11
to joos...@googlegroups.com
Useful toi have M_b

Michael Bradley, Jr.

unread,
Jun 1, 2011, 3:37:34 PM6/1/11
to joos...@googlegroups.com
Well, I must have fooled myself just a bit, because there are still some problems...

Running `node ./index.js` will properly load the REPL with Joose, but "Double declaration" errors are still being thrown during Class definitions.

This works:

$ node ./index.js
> var x = Joose.Class({})


But this doesn't:

$ node ./index.js
> Joose.Class('MyClass', {}) // -> Error: Double declaration of [MyClass]



I think the problem lies, as you've noted before, Nickolay, with the global scope in a node.js REPL environment. The joose code throwing the error is defined in Joose.Namespace.Manager, I think.

It sure would be nice if this worked properly ... I'll try to poke at it, and I'm hoping maybe there is a clever way to do REPL detection along the lines of Joose.is_NodeJS_REPL, and then make some kind of low key automatic adjustment so that Joose works properly.

It would be very convenient for quick-testing if after having fired up joose+REPL I can then require a joose-based packaged I've just built locally with dzil ... test ... .clear REPL ... dzil build... require... test ... .clear REPL .......

Michael Bradley, Jr.

unread,
Jul 2, 2011, 5:55:15 PM7/2/11
to joos...@googlegroups.com
Okay, this was bugging me again today.

I think I've determined the precise problem, but I'm not sure of the solution.


During the `.create()` steps inside Joose and related to `Namespace.Keeper`, certain relationships are tested with `instanceof`.  Per the above post in the node.js google group, `instanceof` can run into problems when used in the REPL as the REPL has its own global context.  This isn't always apparent though, as the global scope in which the REPL is invoked is exposed to the REPL's context.

-------

The following will throw errors in the, but the classes are setup as expected:

myscript.js
  require('task-joose-nodejs')
  repl.start('> ')

$ node ./myscript.js

> var class1 = Joose.Class('class1', {}) // no errors

> class1.class2 = Joose.Class('class1.class2', {})
... throws "Double declaration" error, per Core.js line 2915
... BUT now try ...

> class1.class2.toString() // no errors
'class1.class2'

> var myinst = class1.class2() ; myinst.toString() // no errors
'a class1.class2'

-------

If the steps above are attempted without var declarations, the "Double declaration" errors are thrown and `class1`, `class1.class2` remain undefined.

So the problem seems restricted to Namespace.Keeper (I think).

That being said, I'm not sure how to fix it at this time.

Nickolay Platonov

unread,
Jul 3, 2011, 5:46:13 AM7/3/11
to joos...@googlegroups.com
The `instanceof` check will fail only for built-ins which are different in each context.
Try this code for example (using your repl script):

> var a = new Joose.Namespace.Keeper()
> a instanceof Joose.Namespace.Keeper
true

So I think `instanceof` is not the cause. This is a very weird bug, since Joose reports double declaration for any class name..

Proper solution would be to patch the repl to run/use the caller's context, of course.

Nickolay

--
You received this message because you are subscribed to the Google Groups "Joose" group.
To view this discussion on the web visit https://groups.google.com/d/msg/joose-js/-/0fydamcA8cQJ.

To post to this group, send email to joos...@googlegroups.com.
To unsubscribe from this group, send email to joose-js+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joose-js?hl=en.



--
Nickolay

Reply all
Reply to author
Forward
0 new messages