[Seaside] script: [...] value parameter

Johan Brichau johan at inceptive.be
Thu Oct 27 17:25:58 UTC 2022


Hi Bob,

Good to hear it works out.
Just a note: the order in which you send the `script:` and `callback:value:` (or `callback:passenger:`) blocks to the JQAjax instance does not matter. Seaside will always invoke the `script:` block last since it is the primary callback that generates a response.
The following message orders are equivalent:

| value |
html button
   passenger: self;
   onClick: (html jQuery ajax 
       script: [ :s | ...value is the passenger, which in this case is self… ];
       callback: [ :v | value := v ] passenger: (html jQuery this)


| value |
html button
   passenger: self;
   onClick: (html jQuery ajax 
       callback: [ :v | value := v ] passenger: (html jQuery this);
       script: [ :s | ...value is the passenger, which in this case is self… ]



> On 26 Oct 2022, at 13:26, Bob Nemec <bobn at rogers.com> wrote:
> 
> For those that don't follow Discord, Johan provided a solution with an example that works for me.
> What I needed to position the script: block after the callback:value: block, and have the callback:value: set state that the script: block could use. 
> Seems obvious now... 
> 
> The "script:value:" you are looking for is really the combination of a "callback:value:" with a "script:" on the same ajax request. You can pass the 'closest div passenger' to the script block using temporary variables that get assigned in the callback:value: or callback:passenger: block and then use those in the script: block. If you want to see some example combinations with event delegation you are referring to, you can check out the Todo example: https://github.com/SeasideSt/Seaside/blob/master/repository/Seaside-Examples.package/WATodo.class/instance/renderTodosOn..st <https://github.com/SeasideSt/Seaside/blob/master/repository/Seaside-Examples.package/WATodo.class/instance/renderTodosOn..st>
> On Monday, October 24, 2022 at 08:50:43 a.m. EDT, Bob Nemec <bobn at rogers.com> wrote:
> 
> 
> (Also posted on Discord) ... Thanks: we already use the secondary callbacks & passenger patters. In this case, we have a large calendar component for which we're trying to avoid rendering too much cell specific code (html content gets crazy big).
>   
> Ideally, I'd have one script for the calendar that uses JQueryInstance>>closest: to get the div id / passenger, pass that to a script: [...] block, and then have the browser run the script block result. 
> 
> That works (and we're using it) for static onMouseOver: js script content, but having new content on each mouseover provided by a script: [...] block is where I'm stuck... using the closest: pattern removes the need for cell div specific scripts (with a noticeable render speed  improvement), but I can't pass along the closest div to the script: [...] block to build cell specific content.  
> 
> Feels like it a... 
> script: [:script :value | ...] value: (js script)
> ...pattern should work with a closest: div parameter. Great opportunity for me to learn more Seaside internal :-)  
> 
> Bob
> On Monday, October 24, 2022 at 03:08:24 a.m. EDT, Johan Brichau <johan at inceptive.be> wrote:
> 
> 
> I copy/paste my response on the Discord channel:
> 
> An ajax request with Seaside JQuery can combine multiple secondary callbacks and a single primary callback. You can find out which are which in the method comments on JQAjax. In short: a primary callback is a response-generating callback, while secondary callbacks are callbacks that pass values from the client to the server. As such, you can construct what you want already as follows:
> | value |
> html jQuery ajax 
>    callback: [ :v | value := v ] value: (html jQuery this propertyAt: 'id');
>    script: [ :s | ...use value in the generation of the script... ]
> [9:40 AM]
> Also, take a look at passengers if you want to store objects and retrieve them by id. Seaside has this mechanism built-in for you:
> | value |
> html button
>    passenger: self;
>    onClick: (html jQuery ajax 
>        callback: [ :v | value := v ] passenger: (html jQuery this);
> 
> 
>> On 21 Oct 2022, at 19:48, Bob Nemec <bobn at rogers.com <mailto:bobn at rogers.com>> wrote:
>> 
>> Cross posted from Seaside Discord channel...
>> 
>> I would like to have an 'html ajax script: [...]' method that has a callback:value: pattern. 
>> 
>> Something like... 
>>     html ajax script: [:script :value | ...] value: (html jQuery this propertyAt: 'id') 
>> 
>> Then in the script block 'value' would get the id of 'this', which in an ajax callback is undefined. 
>> This would allow server code to use browser information to build the script. 
>> 
>> Anyone done this?
>> 
>> 
>> Bob Nemec
>> 
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org <mailto:seaside at lists.squeakfoundation.org>
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> 
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org <mailto:seaside at lists.squeakfoundation.org>
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside <http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org <mailto:seaside at lists.squeakfoundation.org>
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside <http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/seaside/attachments/20221027/1c238b58/attachment.html>


More information about the seaside mailing list