[Seaside] Making use of SUElement>>siblings, et al
Stuart Herring
st-lists at stuartherring.com
Sun Jun 3 03:29:38 UTC 2007
Hi All,
I was playing around with SUElement, and noticed that there doesn't
actually seem to be a way to use the results of the methods that
return Enumerables - #siblings, #descendants, etc.
I know there's SUSelector, which implements #do:, #invoke:arguments:
and similar, but only applies to a collection that results from
querying via a selector, not from a collection derived directly from a
relationship to a specific element.
I ended up copying the following methods to make use of them:
SUElement>>each: aBlock
self call: 'each' argument:
(SUFunction on: self canvas block: aBlock arguments:
(Array with: SUElementReference)).
SUElement>>invoke: aString arguments: anArray
self call: 'invoke' arguments: (Array with: aString), anArray
SUElement>>collect: aBlock
self call: 'collect' argument:
((SUFunction on: self canvas block: aBlock arguments:
(Array with: SUElementReference)) return: true).
SUElement>>pluck: aString
self call: 'pluck' argument: aString
I guess #each: should probably really be #do: for consistency with
SUSelector>>do:, but #each: is consistent with the Prototype function
name.
Also, this adds duplication, as the methods are essentially
copy-and-pasted straight from SUSelector - but I'm not sure how best
to factor them out, and since it's only a local modification, I don't
want to go messing with the hierarchy anyway.
In any case - this allowed me to use the following code:
(script element id: id) siblings
each: [ :each | each element removeClassName: #active ]
Or, the invoke equivalent:
(script element id: id) siblings
invoke: #removeClassName arguments: (Array with: #active).
Regards,
Stuart
More information about the Seaside
mailing list