I'm still trying to get my head around "what is the best way to write
javascript in Seaside. I just spent an entire morning and still failed to write the simplest expression via an aggregation of Seaside's JSDecoration's. This is what I want to render: new MyJavascriptObject(document.getElementById("id1")) Using Seasides various brushes and canvas API, I could not even get the first two words right. I tried: html script with: (html javascript create access: 'MyJavascriptObject')) html script with: (html javascript create add: 'MyJavascriptObject')) html script with: (html javascript create alias: 'MyJavascriptObject')) html script with: (html javascript create assign: 'MyJavascriptObject')) None of those produce "new MyJavascriptObject", what am I missing? Its almost like there is a missing JSDecoration or capability missing from JSStatement..? After throwing up my hands with that, I decided to try "hard coding" the Javascript strings into my Seaside rendering methods: html script with: (html javascript script: [ : s | s add: 'new MyJavascriptObject(document.getElementById("', (aPufDomainComponent htmlId),'") ]) which produces: new MyJavascriptObject(document.getElementById(\"id1\") So that is pretty much what I want, but see that it is escaping the quote characters, which makes it hard to read in the browser. Are those necessary or is there some way to avoid that? I wanted to avoid having to put big chunks of hardcoded Javascript strings into my Smalltalk code. Any advice is appreciated. - Chris PS -- I think the inconsistency of the API is part of my struggle. JSObject script: can accept a Block, and WAHtmlCanvas>>#script: SAYS it takes "aBlock", but that HAS to be wrong, because WAScriptTag>>#with: ends up writing the Block's "greaseString" to the stream... thanks. _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Hi Chris,
It is *possible*: html script with: ((html javascript alias: 'MyJavascriptObject') apply: { (html javascript alias: 'document') call: 'getElementById' with: #id1 }) create One important thing to know is that the Seaside script generation api does not cover all possible Javascript expressions. I believe it was never intended to cover the complete language either. We can, of course, always extend the possibilities. Our experience is that it does the job to glue Seaside-JQuery generated expressions to hand-written Javascript, or for small pieces of JS code. If it’s harder to write the JS code in Seaside, then you should not try to write it in Seaside ;) I mean: it’s not as succinct as the concrete syntax because we’re generating something like Javascript ASTs here. I would definitely opt for this version: html script with: (JSStream on: 'new MyJavascriptObject(document.getElementById(''#id1''))’) Alternatively, the following is possible by adding a simple convenience method: html script with: ((html javascript create: (html javascript alias: 'MyJavascriptObject') withArguments: { (html javascript alias: 'document') call: 'getElementById' with: #id1 })) With JSObject>>create:withArguments: implemented as: create: anObject withArguments: aCollection "new <anObject>(<aCollection>)" ^ (anObject apply: aCollection) create Depending on your use case, the other options are: - use handwritten javascript functions and call those from generated scripts, limiting the constructs you need to be generated to those that can be done well in Seaside - generate javascript strings instead of ASTs, as in my final code snippet. - write a complete wrapper library like how it’s done for jQuery to work with your Javascript library. Hope this helps Johan > On 30 Oct 2015, at 17:52, Chris Muller <[hidden email]> wrote: > > I'm still trying to get my head around "what is the best way to write > javascript in Seaside. I just spent an entire morning and still > failed to write the simplest expression via an aggregation of > Seaside's JSDecoration's. This is what I want to render: > > new MyJavascriptObject(document.getElementById("id1")) > > Using Seasides various brushes and canvas API, I could not even get > the first two words right. I tried: > > html script with: (html javascript create access: 'MyJavascriptObject')) > html script with: (html javascript create add: 'MyJavascriptObject')) > html script with: (html javascript create alias: 'MyJavascriptObject')) > html script with: (html javascript create assign: 'MyJavascriptObject')) > > None of those produce "new MyJavascriptObject", what am I missing? > Its almost like there is a missing JSDecoration or capability missing > from JSStatement..? > > After throwing up my hands with that, I decided to try "hard coding" > the Javascript strings into my Seaside rendering methods: > > html script with: (html javascript script: [ : s | s add: 'new > MyJavascriptObject(document.getElementById("', (aPufDomainComponent > htmlId),'") ]) > > which produces: > > new MyJavascriptObject(document.getElementById(\"id1\") > > So that is pretty much what I want, but see that it is escaping the > quote characters, which makes it hard to read in the browser. Are > those necessary or is there some way to avoid that? > > I wanted to avoid having to put big chunks of hardcoded Javascript > strings into my Smalltalk code. Any advice is appreciated. > > - Chris > > PS -- I think the inconsistency of the API is part of my struggle. > JSObject script: can accept a Block, and WAHtmlCanvas>>#script: SAYS > it takes "aBlock", but that HAS to be wrong, because > WAScriptTag>>#with: ends up writing the Block's "greaseString" to the > stream... > > thanks. > _______________________________________________ > seaside mailing list > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
There’s a better version:
html script with: ((html javascript alias: 'MyJavascriptObject') createWithArguments: { (html javascript alias: 'document') call: 'getElementById' with: #id1 }) with the implementation of JSObject>>createWithArguments as follows: createWithArguments: aCollection "new <self>(<aCollection>)" (self apply: aCollection) create We could add these to Seaside 3.2 I think they make sense for generating those pieces of code in a more succinct way. Johan > On 30 Oct 2015, at 20:45, Johan Brichau <[hidden email]> wrote: > > Hi Chris, > > It is *possible*: > > html script with: ((html javascript alias: 'MyJavascriptObject') apply: { (html javascript alias: 'document') call: 'getElementById' with: #id1 }) create > > One important thing to know is that the Seaside script generation api does not cover all possible Javascript expressions. > I believe it was never intended to cover the complete language either. We can, of course, always extend the possibilities. > > Our experience is that it does the job to glue Seaside-JQuery generated expressions to hand-written Javascript, or for small pieces of JS code. > If it’s harder to write the JS code in Seaside, then you should not try to write it in Seaside ;) I mean: it’s not as succinct as the concrete syntax because we’re generating something like Javascript ASTs here. > I would definitely opt for this version: > > html script with: (JSStream on: 'new MyJavascriptObject(document.getElementById(''#id1''))’) > > Alternatively, the following is possible by adding a simple convenience method: > > html script with: ((html javascript create: (html javascript alias: 'MyJavascriptObject') withArguments: { (html javascript alias: 'document') call: 'getElementById' with: #id1 })) > > With JSObject>>create:withArguments: implemented as: > > create: anObject withArguments: aCollection > "new <anObject>(<aCollection>)" > ^ (anObject apply: aCollection) create > > Depending on your use case, the other options are: > - use handwritten javascript functions and call those from generated scripts, limiting the constructs you need to be generated to those that can be done well in Seaside > - generate javascript strings instead of ASTs, as in my final code snippet. > - write a complete wrapper library like how it’s done for jQuery to work with your Javascript library. > > Hope this helps > Johan > >> On 30 Oct 2015, at 17:52, Chris Muller <[hidden email]> wrote: >> >> I'm still trying to get my head around "what is the best way to write >> javascript in Seaside. I just spent an entire morning and still >> failed to write the simplest expression via an aggregation of >> Seaside's JSDecoration's. This is what I want to render: >> >> new MyJavascriptObject(document.getElementById("id1")) >> >> Using Seasides various brushes and canvas API, I could not even get >> the first two words right. I tried: >> >> html script with: (html javascript create access: 'MyJavascriptObject')) >> html script with: (html javascript create add: 'MyJavascriptObject')) >> html script with: (html javascript create alias: 'MyJavascriptObject')) >> html script with: (html javascript create assign: 'MyJavascriptObject')) >> >> None of those produce "new MyJavascriptObject", what am I missing? >> Its almost like there is a missing JSDecoration or capability missing >> from JSStatement..? >> >> After throwing up my hands with that, I decided to try "hard coding" >> the Javascript strings into my Seaside rendering methods: >> >> html script with: (html javascript script: [ : s | s add: 'new >> MyJavascriptObject(document.getElementById("', (aPufDomainComponent >> htmlId),'") ]) >> >> which produces: >> >> new MyJavascriptObject(document.getElementById(\"id1\") >> >> So that is pretty much what I want, but see that it is escaping the >> quote characters, which makes it hard to read in the browser. Are >> those necessary or is there some way to avoid that? >> >> I wanted to avoid having to put big chunks of hardcoded Javascript >> strings into my Smalltalk code. Any advice is appreciated. >> >> - Chris >> >> PS -- I think the inconsistency of the API is part of my struggle. >> JSObject script: can accept a Block, and WAHtmlCanvas>>#script: SAYS >> it takes "aBlock", but that HAS to be wrong, because >> WAScriptTag>>#with: ends up writing the Block's "greaseString" to the >> stream... >> >> thanks. >> _______________________________________________ >> seaside mailing list >> [hidden email] >> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside > _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by Chris Muller-4
The argument name of WAHtmlCanvas>>script: is indeed wrong. I guess this was a copy/paste issue. Thanks for spotting. Will fix that. Johan _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by Johan Brichau-2
> One important thing to know is that the Seaside script generation api does not cover all possible Javascript expressions.
I wasn't sure, good to know. > I believe it was never intended to cover the complete language either. We can, of course, always extend the possibilities. > > Our experience is that it does the job to glue Seaside-JQuery generated expressions to hand-written Javascript, or for small pieces of JS code. > If it’s harder to write the JS code in Seaside, then you should not try to write it in Seaside ;) I mean: it’s not as succinct as the concrete syntax because we’re generating something like Javascript ASTs here. True, but I am attracted to the idea of generating it via Smalltalk messages because (1) I think that approach provides me easier opportunities for factoring and reuse, plus (2) I don't end up with "two languages", each with their own syntax, in one method, which becomes VERY difficult to read and maintain because I can't use my IDE's capability to "select expressions" inside (parens), [brackets], 'quotes', etc. > I would definitely opt for this version: > > html script with: (JSStream on: 'new MyJavascriptObject(document.getElementById(''#id1''))’) One of my reservations about that is it bypasses the brush API, which is not only the prescribed way to use Seaside, it also sets up some state on the Canvas ('currentBrush') which might be needed..? So, can I do that going through the Brush api? Everything I try causes the various HTML characters to be escaped... > Alternatively, the following is possible by adding a simple convenience method: > > html script with: ((html javascript create: (html javascript alias: 'MyJavascriptObject') withArguments: { (html javascript alias: 'document') call: 'getElementById' with: #id1 })) > > With JSObject>>create:withArguments: implemented as: > > create: anObject withArguments: aCollection > "new <anObject>(<aCollection>)" > ^ (anObject apply: aCollection) create I think I like that.. > Depending on your use case, the other options are: > - use handwritten javascript functions and call those from generated scripts, limiting the constructs you need to be generated to those that can be done well in Seaside > - generate javascript strings instead of ASTs, as in my final code snippet. > - write a complete wrapper library like how it’s done for jQuery to work with your Javascript library. > > Hope this helps Indeed, thanks. _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |