common javascript across multiple widgets

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

common javascript across multiple widgets

shepa006
I'm building a set of widgets based on the tutorial from esri, https://developers.arcgis.com/javascript/jshelp/intro_custom_dijit.html. I've been able to set up multiple widgets in the same directory and pull them in as a package in the dojoConfig. This helps with using AMD to specify which widget(s) from the package I need for a specific page.

I'm wondering if there's a way to create a javascript file of common features that could be used across any of the widgets. Is there a javascript equivalent to dojo/text!application/ or another best practice for including a js file?
rhp
Reply | Threaded
Open this post in threaded view
|

Re: common javascript across multiple widgets

rhp
Maybe the answer is simpler than you think?

Define your common features in a module (commonFeatures.js):

    define([ ... dependencies ... ], function( ... ) {
        return <common features>;
    });

And use them in another module:

    define([ ... dependencies ..., 'myapp/commonFeatures'] ...

Is this what you are looking for?

Ronald

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of shepa006
Sent: 2015 Mar 10 15:20
To: [hidden email]
Subject: [Dojo-interest] common javascript across multiple widgets

I'm building a set of widgets based on the tutorial from esri, https://developers.arcgis.com/javascript/jshelp/intro_custom_dijit.html.
I've been able to set up multiple widgets in the same directory and pull them in as a package in the dojoConfig. This helps with using AMD to specify which widget(s) from the package I need for a specific page.

I'm wondering if there's a way to create a javascript file of common features that could be used across any of the widgets. Is there a javascript equivalent to dojo/text!application/ or another best practice for including a js file?



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/common-javascript-across-multiple-widgets-tp4005564.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: common javascript across multiple widgets

shepa006
I think that is what I was looking for. I'll play around with it a bit. Clearly I haven't done this before so thanks for the snippets to get me started. 
I was surprised that I couldn't find a tutorial or example that showed how this works, or more likely I just couldn't get the right keywords in my searches.
Justin

On Tue, Mar 10, 2015 at 9:00 AM, rhp [via Dojo Toolkit] <[hidden email]> wrote:
Maybe the answer is simpler than you think?

Define your common features in a module (commonFeatures.js):

    define([ ... dependencies ... ], function( ... ) {
        return <common features>;
    });

And use them in another module:

    define([ ... dependencies ..., 'myapp/commonFeatures'] ...

Is this what you are looking for?

Ronald

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of shepa006
Sent: 2015 Mar 10 15:20
To: [hidden email]
Subject: [Dojo-interest] common javascript across multiple widgets

I'm building a set of widgets based on the tutorial from esri, https://developers.arcgis.com/javascript/jshelp/intro_custom_dijit.html.
I've been able to set up multiple widgets in the same directory and pull them in as a package in the dojoConfig. This helps with using AMD to specify which widget(s) from the package I need for a specific page.

I'm wondering if there's a way to create a javascript file of common features that could be used across any of the widgets. Is there a javascript equivalent to dojo/text!application/ or another best practice for including a js file?



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/common-javascript-across-multiple-widgets-tp4005564.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



If you reply to this email, your message will be added to the discussion below:
http://dojo-toolkit.33424.n3.nabble.com/common-javascript-across-multiple-widgets-tp4005564p4005565.html
To unsubscribe from common javascript across multiple widgets, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: common javascript across multiple widgets

Karl Tiedt
You could look at any of the dojo/* modules for an example of this... such as dojo/fx which is used by widgets and non widgets... 

-Karl Tiedt

On Tue, Mar 10, 2015 at 9:19 AM, shepa006 <[hidden email]> wrote:
I think that is what I was looking for. I'll play around with it a bit. Clearly I haven't done this before so thanks for the snippets to get me started. 
I was surprised that I couldn't find a tutorial or example that showed how this works, or more likely I just couldn't get the right keywords in my searches.
Justin

On Tue, Mar 10, 2015 at 9:00 AM, rhp [via Dojo Toolkit] <[hidden email]> wrote:
Maybe the answer is simpler than you think?

Define your common features in a module (commonFeatures.js):

    define([ ... dependencies ... ], function( ... ) {
        return <common features>;
    });

And use them in another module:

    define([ ... dependencies ..., 'myapp/commonFeatures'] ...

Is this what you are looking for?

Ronald

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of shepa006
Sent: 2015 Mar 10 15:20
To: [hidden email]
Subject: [Dojo-interest] common javascript across multiple widgets

I'm building a set of widgets based on the tutorial from esri, https://developers.arcgis.com/javascript/jshelp/intro_custom_dijit.html.
I've been able to set up multiple widgets in the same directory and pull them in as a package in the dojoConfig. This helps with using AMD to specify which widget(s) from the package I need for a specific page.

I'm wondering if there's a way to create a javascript file of common features that could be used across any of the widgets. Is there a javascript equivalent to dojo/text!application/ or another best practice for including a js file?



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/common-javascript-across-multiple-widgets-tp4005564.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



If you reply to this email, your message will be added to the discussion below:
http://dojo-toolkit.33424.n3.nabble.com/common-javascript-across-multiple-widgets-tp4005564p4005565.html
To unsubscribe from common javascript across multiple widgets, click here.
NAML



View this message in context: Re: common javascript across multiple widgets

Sent from the Dojo Toolkit mailing list archive at Nabble.com.

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: common javascript across multiple widgets

shepa006
In case anyone else is looking to do this I looked through the dojo files like Karl suggested and here's what I came up with.
Folder structure:
Root
  -common
     myFunctions.js
  -dijit (folder holds templates for my widgets)
  widget.js

widget.js:
define(
    ["./common/myFunctions",...],
    function(functions,...){
       ...
       constructor: function (options, srcRefNode) {
            try {
                this.common = new functions();
                this.common.testFunction({ "this.common": this.common });
            } catch (e) {
                console.error("build common functions failed", e);
            }
            ...
       },
       ...
   }
);
Reply | Threaded
Open this post in threaded view
|

Re: common javascript across multiple widgets

Karl Tiedt
If you are specifically doing widgets,

Look at the _*Mixin*.js classes under dijit, defnitely not the cleanest solution for widgets ;)

-Karl Tiedt

On Tue, Mar 24, 2015 at 1:54 PM, shepa006 <[hidden email]> wrote:
In case anyone else is looking to do this I looked through the dojo files
like Karl suggested and here's what I came up with.
Folder structure:
Root
  -common
     myFunctions.js
  -dijit (folder holds templates for my widgets)
  widget.js

widget.js:
define(
    ["./common/myFunctions",...],
    function(functions,...){
       ...
       constructor: function (options, srcRefNode) {
            try {
                this.common = new functions();
                this.common.testFunction({ "this.common": this.common });
            } catch (e) {
                console.error("build common functions failed", e);
            }
            ...
       },
       ...
   }
);



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/common-javascript-across-multiple-widgets-tp4005564p4005738.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: common javascript across multiple widgets

shepa006
Thanks for the pointer. As you can tell I'm still learning :) Any positive input or suggestions are welcome and if you have any suggestions for good examples on how to do things let me know. I keep looking for complete tutorials to help me get started with being more proficient with Dojo but most of what I find is snippets rather than complete functional examples. I find the documentation in the toolkit good but fairly hard for me to put the pieces together in the best way as I'm learning, so I fumble around a lot.

As for this particular topic, I was really trying to think of how I could create a resource for use in widgets or as a stand alone set of functions that could be used by anything. So I'll look into the mixin class some more and hopefully clean this up.

As long as we're chatting, any suggestions on unit testing? I've heard people mention using DOH or Intern but I haven't used either of those before. I want to try and make sure that what I set up for this 'common' resource is easy to test and I don't do something silly that later on makes me go 'dang it, if I had realized that I would have set this whole thing up differently in the beginning'

Cheers and thanks for the help.