Using a different Attribute class

6 views
Skip to first unread message

nickf

unread,
Nov 26, 2010, 8:21:11 AM11/26/10
to Joose
Is it possible to extend the Joose.Managed.Attribute class? How would
you make a class and its subclasses use that new Attribute type for
its own attributes?

I've seen the 'defaultAttributeClass' property of
Joose.Managed.Attribute.Builder, but if I change that, then all
Classes will use the new Attribute class, which is not what I'm after.

Nickolay Platonov

unread,
Nov 26, 2010, 8:41:14 AM11/26/10
to joos...@googlegroups.com
On Fri, Nov 26, 2010 at 4:21 PM, nickf <spa...@gmail.com> wrote:
Is it possible to extend the Joose.Managed.Attribute class?

Sure. You can either subclass it or create a role for it. For the examples see: https://github.com/SamuraiJack/JooseX-Attribute/blob/master/lib/JooseX/Attribute/Lazy.js
and other roles in that distro.
 
How would you make a class and its subclasses use that new Attribute type for
its own attributes?
 
I've seen the 'defaultAttributeClass' property of
Joose.Managed.Attribute.Builder, but if I change that, then all
Classes will use the new Attribute class, which is not what I'm after.

Yes, `defaultAttributeClass` attribute is what you are looking for. You can change it for specific class in two ways:

1) Create a new meta-class:

Class('My.Meta.Class', {
   
    meta    : Joose.Meta.Class,
  
    isa     : Joose.Meta.Class,
   
    have    : {
        defaultAttributeClass : MyAttributeClass
    }
})



Class('My.Usual.Class', {
   
    meta : My.Meta.Class,
   
    has : {
        attr : {} // will create MyAttributeClass
    }

})


2) Create a trait:

Role('My.Trait', {
   
    have    : {
        defaultAttributeClass : MyAttributeClass
    }
})


Class('My.Usual.Class', {
   
    trait : My.Trait,
   
    has : {
        attr : {} // will create MyAttributeClass
    }

})


3) Also, if you'll create a *role* for attribute, you can apply it as trait for some particular attribute:
Other attributes won't be affected.

Role('My.Attribute.Role', { ... })


Class('My.Usual.Class', {
   
    has : {
        attr : {
            trait   : My.Attribute.Role,
           
            ...
        }
    }

})
 

Regards, Nickolay

nickf

unread,
Nov 26, 2010, 10:42:52 AM11/26/10
to Joose
Hi Nicholay,

Thanks for the speedy response. As a newbie with Joose, the support is
very welcome!

On Nov 26, 2:41 pm, Nickolay Platonov <nickol...@gmail.com> wrote:
> On Fri, Nov 26, 2010 at 4:21 PM, nickf <spad...@gmail.com> wrote:
> > Is it possible to extend the Joose.Managed.Attribute class?
>
> Sure. You can either subclass it or create a role for it. For the examples
> see:https://github.com/SamuraiJack/JooseX-Attribute/blob/master/lib/Joose...

Nickolay Platonov

unread,
Nov 26, 2010, 10:52:13 AM11/26/10
to joos...@googlegroups.com
np, you are welcome, btw, there is also #joose on freenode

--
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.


Reply all
Reply to author
Forward
0 new messages