Coder Social home page Coder Social logo

AMD support about hideshowpassword HOT 7 CLOSED

cloudfour avatar cloudfour commented on June 24, 2024
AMD support

from hideshowpassword.

Comments (7)

tylersticka avatar tylersticka commented on June 24, 2024

@timmywil That's a great idea!

from hideshowpassword.

tylersticka avatar tylersticka commented on June 24, 2024

Hey @timmywil, maybe you can help me with something... I'm a designer first and a developer second, so it's hard for me to judge the best way to tackle this from a developer perspective... especially since I've never used RequireJS before!

hideShowPassword works with either jQuery or Zepto. This is easy enough in the current version of the plugin, as I can just pass this.jQuery || this.Zepto for the $ argument and call it a day. But in the case of defining dependencies, it looks like I have to be a bit more overt.

This post suggests doing something like this:

define(('__proto__' in {} ? ['zepto'] : ['jquery']), function($) {
    return $;
});

This makes sense to me if your library overtly recommends the use of both Zepto and jQuery, but my goal in writing the plugin that way was flexibility... I would guess most users will be favoring jQuery, so it seems a pretty big assumption to say "when '__proto__' in {} returns something truthy, always use Zepto."

I apologize if this is a newb question, but how would you recommend supporting both frameworks?

from hideshowpassword.

timmywil avatar timmywil commented on June 24, 2024

No problem! I'd recommend something like this:

(function (factory, global) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        // To use Zepto, map Zepto to the the name 'jquery' in your paths config
        define(['jquery'], factory);
    } else {
        // Browser globals
        factory(global.jQuery || global.Zepto);
    }
}(function ($) {
    // hideShowPassword code here
}, this));

AMD folks who use Zepto are used to mapping zepto already because Zepto doesn't register as an AMD module (much to the objection of Zepto's users and the front-end community). I would simply document that using zepto instead is a matter of path config:

require.config({
  paths: {
    jquery: 'path/to/zepto'
  }
});

This will map Zepto to the name 'jquery' and the define call will pull in Zepto for the $ variable instead.

from hideshowpassword.

tylersticka avatar tylersticka commented on June 24, 2024

@timmywil Perfect. Thanks so much for the detailed explanation... knowledge is awesome. :)

from hideshowpassword.

tylersticka avatar tylersticka commented on June 24, 2024

@timmywil Okay, I think I have this working... but just in case, I pushed to an amd-support branch.

If you get a moment, would you mind taking a look or giving it a whirl before I unleash it on an unsuspecting populace?

from hideshowpassword.

timmywil avatar timmywil commented on June 24, 2024

👍 I just tested and it works great! Thanks!

from hideshowpassword.

tylersticka avatar tylersticka commented on June 24, 2024

@timmywil Sweet! Branch merged, release tagged, and bob's your uncle. Thanks again for your help.

from hideshowpassword.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.