Thats odd. I've been noticing my emails to the list appear after a delay -
not sure whats causing it. And now the code disappears! But thanks for your
help.

Anyways, in the meantime I already started playing with modules and
require.js and got it to work. I have a few questions though. I'm not a
great javascript programmer but I find the AMD approach refreshing and very
clean. So +1 for AMD in 5.4!

I struggled somewhat finding the right syntax to use between require.js,
jquery and mixins! So, using my open street maps example, here is what I
did (and I hope code goes through this time):

To monitor any changes to the textfield component, I defined a mixin:

<t:textfield t:id="addressLineTwo" t:mixins="OpenStreetMaps"/>

In the implementation, class - invoked the module/javascript initialization:

javaScriptSupport.require("openstreetmaps").invoke("registerAddressChangeListener").with(clientElement.getClientId());

and in the openstreetmaps.js:


define('openstreetmaps', [ 'open-layers', 'jquery', 't5/core/console' ],
function(
openLayers, $, console) {

return {

showMap : function(clientId) {
var map = new openLayers.Map(clientId);
map.addLayer(new openLayers.Layer.OSM());
map.addLayer(new openLayers.Layer.Markers("Markers"));
map.zoomToExtent();

},

registerAddressChangeListener : function(clientId) {
$('#addressLineTwo').on('input propertychange paste',function() {
require([ 'open-layers' ], function(openLayers) {
console.debug(openLayers);
})});
}

};

});

My question/concern is around the code I wrote in
registerAddressChangeListener. To update the map, I have to use the
open-layers module. Now, as far as my understanding goes, there is no
clean/easy way to store a 'reference' to that module locally the openLayers
module (please correct me here!). So the only way is to define a function,
which in turn defines in a function in the format:

require(['dependencies'], function(dependencies) {..}


The parameter from the define method is available in the return closure
functions, but as this is an event handler that gets called randomly, the
context changes and that variable is not available anymore? The tapestry
JavaScriptSUpport class also seems to follow the same pattern...calling
require('module name').invoke('parameters').

I guess this more of a Javascript question than a tapestry question - but
spent last few hours searching for this and could not find anything. Would
appreciate any help on this matter.


Best Regards,
Sanket

















On Mon, Jun 16, 2014 at 4:05 PM, Thiago H de Paula Figueiredo <
thiag...@gmail.com> wrote:

> On Sun, 15 Jun 2014 21:35:34 -0300, Sanket Sharma <sanketsha...@gmail.com>
> wrote:
>
>  Hi,
>>
>
> Hi!
>
>  Now, in my application I have a open street map control that needs to be
>> updated when a selection/text changes on the form. I was wondering what
>> is the best way to do it in T5.4?
>> I can potentially create a Mixin as described in jumpstart:
>>
>
> The code you pasted in your e-mail didn't make it to the mailing list, so
> we cannot comment on it.
>
> Mixins are a very powerful and interesting tool. The scenario you describe
> seems a good match for a mixin.
>
>  Not sure if that is the best way? I can also inject script directly
>> using javaScriptSupport.addScript
>> or can create a module that gets loaded and initiated when the page
>> finishes loading..
>>
>
> JavaScriptSupport.addScript() is deprecated, so a module is the way to go
> in 5.4.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to