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 _______________________________________________ Seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
> 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. Probably not. I added those methods for completeness, but never used them myself. Obviously these are not well integrated with the rest of the framework. > 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 was not happy with the solution of SUSelector, never used it myself and didn't know of anybody else using it. > 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. You are asking for traits and this is not the the only place where we have duplication in Seaside and Scriptaculous ;-) In this particular case it would be maybe better to factor out the functionality to an enumerator object. I am thinking of something along: (html element id: 'foo') siblings enumerator do: [ :each | ... ] This would make more sense as it would not clutter SUElement with enumeration code, as SUElement itself is not enumerable. > 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). Please commit changes to the Seaside repository. And add some tests ;-) Lukas -- Lukas Renggli http://www.lukas-renggli.ch _______________________________________________ Seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |