-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Refactors Backbone to support multiple design patterns and a more consistent code-base for any project. #2718
Conversation
…istent with any project codebase, Implements Backbone.State, REST-less super class for Backbone.Model, Implements Backbone.BaseView to provide a base View class for any other pattern - super class for Backbone.View, Refactors Backbone.Collection and backbone.Router to inherit from Backbone.Base super class
Why isn't the diff visible on this PR? |
I have no clue... Maybe too many changes? Is that possible? |
Mind attaching a diff as a gist, here? |
Sure, let me grab some dinner. =) |
Git doesn't like the whitespace difference. Try with Unfortunately no line-commenting this way though. |
Many of the ideas in this pull have been brought up in different forms in the past. BaseView / Base Class (#276, #1816, #2413), stateful attributes (#1442, #2526, #2557), and |
Yes, I thought maybe I shouldn't do this but the end I was kinda "forced". Reasons for that: 1: I like Backbone as it is, provides the features I need in a simple way. =) 2: I needed a code-base which is consistent (company requirement) so I don't end up maintaining classes written in 2 types of coding-styles (Backbone and "native" JavaScript style) 3: I also found myself segregating the logic from the View into a Controller (sometimes the Model too) to separate business logic and View specific logic because I might want to notify other components about Model changes, View events/changes, or notify a service about something. 4: I don't always use the REST features on the Models, even if I very much like the way Backbone does that. Model emits events for changes so I need those features separate. I know that I should override the default methods with my persistence or async layer on my models but that doesn't feel natural. I understand that Backbone is not meant to be a "class library for JavaScript" and "the way that you desire to structure the rest of your app is up to you". I want to keep Backbone but sometimes I also need to deviate from the original MV pattern. |
Its pretty easy to "borrow" the bits you need from the library where you need them: var MyClass = function(attrs, options) {
...
}
MyClass.extend = Backbone.Model.extend; Check out the plugin I wrote for #2557 if, for example, you need stateful attributes in your collections or views. Or if you want a model devoid of RESTful features, you could create a base Model where Backbone is about as non-magic / non-opinionated as frameworks come, and should play nicely with all of the rest of your code. How you structure your application and use its utilities are up to you. |
With respect, that is exactly what I wanted to avoid. I cannot provide a code-base which starts like that for any client. How about exposing the extend method properly? |
It is exposed — as For better or worse, Backbone encourages extension of its core components for maximum usefulness. Fortunately, the API has been fairly static since the early versions, so your extensions and plugins should work version-to-version. Attempting to keep up with the library after modifying it directly, on the other hand, is a sure-fire path to frustration. |
Hi @benqus, thanks for the patch!
Yep yep, |
I am sorry to read that. I won't be able to pass Backbone this way to the architecture.
Seems we have to find our own ways of doing stuff. MIT license is cool for many things. =) Anyway, worth a try. Cheers guys! |
+1 @benqus that's something I really wish for and I found myself pretty lame after rolling out my own extension of backbone. There are behaviors already implemented but you can't easily reuse them without workarounds to avoid code duplication.. Granularity only comes for good. It's like say: "okay, if you want to roll out your own version just grab those modules and build your own 'backbone like' thing, instead we have some builtin solutions like Backbone.Model, Backbone.Collection and Backbone.View, good luck." Well, I thought of forking to do my own thing but, in the mean time it only creates more issues and you will have to give up all the great backbone community behind to be responsible by maintaining it.. for that case I rather switch libraries than hack things out. |
Thanks @mateusmaso Having a second thought about "How structure your application and use its utilities are up to you" would be true, if Backbone would not depend on jQuery and underscore massively. Fine, you don't get basic templating (underscore), neat Model/Collection API (70% underscore), async stuff (jQuery), etc... But still. Being so much dependent means that backbone defines what utilities I want to use. Creating a Model class, which overrides the sync method and does nothing is not a good idea... I personally prefer MVC or MVP but in Backbone style. It makes more sense for me and I have my Model specific, View specific and business (holaaa) logic segregated which improves code transparency, shortens my classes resulting in better structured apps. Of course, this (just like everything else too) can be overdone. Again, I might be wrong on this and I probably don't consider every aspect the decision-makers have to. =) I considered Angular, Maria, Ember etc., but they are so much want to be the application and define everything I want... That is exactly the reason why I wanted to stick with Backbone. I think Backbone is an awesome idea, with very nice implementation (even if it highly depends on 2 other libs), all I need is a bit more flexibility. =) |
Mostly agree with @benqus. The main reason to use Backbone instead of Angular etc is the freedom to extend and use the components as we see fit. That could be improved further by exposing some internals like Backbone.extend and Events. I just forked Backbone because I also wanted to add a Backbone.Base object that implements Events and extend. Guess that any PR I was about to make won't be accepted then :( |
Implements Backbone.Base class to provide a base class for being consistent with any project codebase,
Implements Backbone.State, REST-less super class for Backbone.Model,
Implements Backbone.BaseView to provide a base View class for any other pattern - super class for Backbone.View,
Refactors Backbone.Collection and backbone.Router to inherit from Backbone.Base super class