Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be module-friendly #158

Open
efc-awebb opened this issue Mar 24, 2015 · 11 comments
Open

Be module-friendly #158

efc-awebb opened this issue Mar 24, 2015 · 11 comments

Comments

@efc-awebb
Copy link

These classes can be made module-friendly by using a wrapper like this (credit to @sheppard).

(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD
        define(['leaflet'], factory);
    } else if (typeof module !== 'undefined') {
        // Node/CommonJS
        module.exports = factory(require('leaflet'));
    } else {
        // Browser globals
        if (typeof this.L === 'undefined')
            throw 'Leaflet must be loaded first!';
        factory(this.L);
    }
}(function (L) {

L.BingLayer = /* ... */

return L.BingLayer;

}));

This would enable, for example:

var L = require('leaflet');

// Add BingLayer support
var BingLayer = require('./node_modules/leaflet-plugins/layer/tile/Bing');
BingLayer(L);

As it stands, developers writing modular code would have to either monkey-patch that wrapper into place or set up a shim to convert the code into a modular form - neither of which is particularly desirable.

@dmitry
Copy link

dmitry commented Jul 21, 2015

👍 nice idea!

@johnd0e
Copy link
Contributor

johnd0e commented Jul 10, 2019

This is mentioned in Leaflet's official PLUGIN-GUIDE.md

@brunob
Copy link
Collaborator

brunob commented Jul 24, 2019

I'm on it...

@johnd0e
Copy link
Contributor

johnd0e commented Jul 24, 2019

But I do not think that mentioned pattern should be put directly into source files.
Better if it'd done in some build process.

@brunob
Copy link
Collaborator

brunob commented Jul 24, 2019

We don't have build script and i think this is oversized to use one for that.

brunob added a commit that referenced this issue Jul 24, 2019
Fix #158 for layer scripts, still have to do it for tiles scripts
@johnd0e
Copy link
Contributor

johnd0e commented Jul 24, 2019

Well, if you prefer to see same ugly pattern in ~15 source files, instead of simple build script..

@brunob
Copy link
Collaborator

brunob commented Jul 24, 2019

@johnd0e
Copy link
Contributor

johnd0e commented Jul 24, 2019

I like KISS, but not WET.

How about DRY https://en.m.wikipedia.org/wiki/Don't_repeat_yourself?

@brunob
Copy link
Collaborator

brunob commented Jul 25, 2019

huhu, sorry but i prefer to keep the release process simple (push a tag & publish to npm).

Anyway, feel free to provide a PR or an issue to describe the build process you would like to use.

@gelinger777
Copy link

related to #267

@GhadaAJIMI
Copy link

As a user of this pluggin do I have to do this to inclure the rotate function into leaflet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants