[joose] Parameterized Role question

3 views
Skip to first unread message

John Mark Hawley

unread,
Dec 8, 2010, 2:42:20 PM12/8/10
to joos...@googlegroups.com
I'm trying to roll up a simple Logging role based off of the example
given on https://github.com/SamuraiJack/JooseX-Role-Parameterized.

My code:

Role('Loggable', {

use: ['JooseX.Role.Parameterized'],
meta: 'JooseX.Role.Parameterized',
parameter: {
logMethodsMatching: null
},
introspect: true,
role: function (self, consumer) {

if (null == self.logMethodsMatching)
{
return;
}

var role = {
override: {}
}

var methods = consumer.meta.getMethods();
methods.eachOwn(function (method, name) {

if (self.logMethodsMatching.test(name)) {
console.log('Call to method [' + name + '] - with
arguments [' + Array.prototype.slice(arguments) + ']')

var res = self.SUPERARG(arguments)

        console.log('Returned result [' + res + ']')
        return res;
}
});
return role;
}
});

...applied to this class:

Class('StartGameAction', {

// should apply to all instance methods
does: [com.nilbog.utility.role.Loggable({ logMethodsMatching: /^.+$/ })],
isa: m.Action,
has: {
gameDescription: { is: 'ro', required: true },
subActions: { is: 'ro', init: Joose.I.Array }
},
methods: {
execute: function () {
// removed
},
undo: function () {
// removed
},
startGame: function () {
// removed
}
}
});

Two problems:

1) The line 'var res = self.SUPERARG(arguments)' causes the error
'Invalid call to SUPER'
2) Without that line, I see the role is being applied to even the
generated accessors getGameDescription and getSubActions, which
SamuaiJack tells me should be impossible.

Any hints? S.Jack also recommended trying to implement Loggable as a
Meta Role that changes the default meta class of each instance method
instead. Has anyone gone this route?


--
John Mark Hawley
Design Technologist, Nilbog Group
http://www.nilbog.com
AIM: jmhnilbog
Twitter: johnmarkhawley

Malte Ubl

unread,
Dec 12, 2010, 11:19:07 AM12/12/10
to joos...@googlegroups.com
Nickolay, can you help?

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

--
http://twitter.com/cramforce
http://nonblocking.io

Nickolay Platonov

unread,
Dec 12, 2010, 11:28:00 AM12/12/10
to joos...@googlegroups.com
Sure, we've sorted that out in IRC, so I didn't follow up here. Here's the working version if someone is interested: http://pastie.org/1359904
Reply all
Reply to author
Forward
0 new messages