Removing the jquery/zepto dependency on backbone.router and views

前端 未结 3 2020
走了就别回头了
走了就别回头了 2021-02-10 03:18

Is there a forked/maintained version of backbone that completely eliminates the need for jquery or zepto to use both the router and views?

I wouldn\'t mind using backbon

相关标签:
3条回答
  • 2021-02-10 04:02

    Yup here's one: https://github.com/inkling/backbone.native. It's a tiny adapter that allows Backbone to work while relying on only native DOM APIs.

    0 讨论(0)
  • 2021-02-10 04:14

    If you want Backbone to handle DOM manipulation, DOM events, and AJAX requests, then you'll need another library to do this. It doesn't have to be jQuery or Zepto - Backbone also supports Ender, and you could theoretically use any library that can do DOM selection and supports a subset of jQuery-style methods. A quick look through the annotated source code shows that you need the following methods:

    • $(selector)
    • $.ajax()
    • $(selector).find()
    • $(selector).bind()
    • $(selector).unbind()
    • $(selector).delegate()
    • $(selector).remove()
    • $(selector).attr()
    • $(selector).html()

    If you don't want Backbone to deal with this stuff, you can pretty easily remove the requirements by overwriting the methods that use them - e.g. you can dispense with .attr() and .html() by setting Backbone.View.prototype.make = function() {}. Or just don't use Backbone.View - that removes the need for everything but $.ajax() (unless you're using pushState, in which case you need event binding too).

    0 讨论(0)
  • 2021-02-10 04:21

    You can try to use jBone, this is library for DOM manipulations in modern browsers, jBone developed special for Backbone, only 2kb gzipped and jQuery like API.

    0 讨论(0)
提交回复
热议问题