Stamplay JS SDK puts itself into the global scope and expects its dependencies to be available in the global scope. In 2016, polluting the global scope is considered to be a bad practice. All major frameworks are 100% modularized and don't rely on any globals.
The SDK relies on Underscore and Q, while the host app might be already requiring their alternatives: Lodash and RSVP/Bluebird/etc. It is kinda humiliating and inefficient to be forced to include all four dependencies when you need only two.
Suggested solutions
Use a UMD module! https://github.com/umdjs/umd It's just a code snippet that you wrap your library with -- and your library automatically detects globals/AMD/CommonJS at runtime! That's a no-brainer really. You can provide a UMD-wrapped version in addition to existing builds, so that you don't do a potentially breaking change.
This one's tougher. The SDK already allow replacing the Q dependency -- all you need to do is to redefine the Stamplay.makePromise method. But as for Underscore, the SDK uses the _ global immediately after the SDK script is included. The only way to substitute it is to provide your own _ global before including the SDK.
But my Lodash lib is an AMD module and it's not available at the moment the SDK is included. And I do not want to touch any globals in the first place.
I don't know a definite solution for this problem. Here are a couple of ways to consider:
Let the user build it's own version of the SDK, configuring dependency module names.
Tell the user to reexport their Lodash and RSVP/Bluebird modules under the names of Q and Underscore modules respectively.
Guys, use :arrow_lower_left: reaction emojis to express your demand for this feature! Don't flood the thread with +1 comments!
(moved from https://github.com/Stamplay/stamplay-product-development/issues/8)
Problems
Suggested solutions
This one's tougher. The SDK already allow replacing the Q dependency -- all you need to do is to redefine the
Stamplay.makePromise
method. But as for Underscore, the SDK uses the_
global immediately after the SDK script is included. The only way to substitute it is to provide your own_
global before including the SDK.But my Lodash lib is an AMD module and it's not available at the moment the SDK is included. And I do not want to touch any globals in the first place.
I don't know a definite solution for this problem. Here are a couple of ways to consider:
Guys, use :arrow_lower_left: reaction emojis to express your demand for this feature! Don't flood the thread with +1 comments!