Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed via email, this PR converts all the AMD modules into their ES module equivalents. It's probably not ready to merge in its current state (e.g. I haven't updated the tests, though I have updated all the examples and they still work
with one exception, more on which below), but it's a starting point for the sake of discussion.Benefits:
It doesn't introduce any ES6 features other than
import
andexport
, so there's still no need to transpile the code with Babel, if that's not desirable. Thesrc
folder was generated with convert-samsara-to-es, so that it can be re-run following any future changes.Resulting dist file is here (compare to original).
The only theoretical downside is that AMD users can no longer import an individual module directly from the source, but instead require the entire UMD bundle. I'd argue that it's not such a loss – most of the examples end up depending on almost every module anyway, so they fetch almost as many bytes but spread over several dozen requests, and in any case if you were to adopt other ES6 language features as per #18 then you'd lose the build-free benefit of AMD anyway. That being said, it would be fairly trivial to create a directory of AMD modules from the ES module source at publish time, if necessary.
As well as the UMD build, this PR introduces a
jsnext:main
build, which is identical to the UMD build except that it uses theexport
statement rather than supporting CommonJS, AMD and globals. This is very beneficial for consumers of the library who are using ES6-aware tooling, as it allows any unused classes etc to be tree-shaken off.jsnext:main
is a convention that's been adopted by a few major libraries (D3, Redux, lodash etc). One consequence of distributing an ES module is that a library can't have nested namespaces (likeSamsara.DOM
) – instead, everything exists in the top-level namespace:In my view this might actually be better, because it's no longer necessary to remember whether
Scrollview
belongs to theDOM
namespace orLayouts
(for example), which makes learning and remembering the library much easier, and you have more freedom to alter the project structure without breaking people's apps. But if you think this is a change too far it's easy enough to maintain the current nested namespaces (it's just less future-proof, because it goes against the grain of ES modules).There is one odd thing I've just noticed: the SideMenu demo no longer registers the drag gesture. No error is reported. Possibly an order-of-execution thing – will keep prodding it and see if I can work out what happened. Everything else appears to work identically.fixed by #20Anyway, thanks for reading this far, this was a far more rambly PR than I planned 😅