jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.1k stars 5.38k forks source link

If you could change Backbone at will, how would you? #4290

Open jgonggrijp opened 4 months ago

jgonggrijp commented 4 months ago

Sooner or later, there will be a Backbone 2.0. Major releases are disruptive for users, so I prefer to make them as infrequently as possible. But when we do one anyway, we might as well use it to its full potential.

This is a "wild ideas" ticket, where you can suggest any backwards-incompatible changes that you would like to see in a future release of Backbone. Please keep it brief, but do explain why you would like to see the change(s) that you suggest.

You are also welcome to highlight anything that you want to stay the same. Again, please with reasons.

Some rules of the game:

The following prior tickets are somewhat related: #4274, #4245, #3560.

jdittrich commented 4 months ago

What to keep: It seems that backbone is the only MVC-Framework for JavaScript that is still updated, so I would not change anything about that paradigm.

What to keep/Improve: Use of ESModules without introducing the Backbone global or a build tool – #4274

What to improve: Use of ES6 classes (So I can class myModel extends BackboneModel{…})and staticmethods when using Backbone (instead of _extend(…)). Caveat: That might work already, but #4213 and #3560 seem to point to some possible problems and are still open. We have preinitialize but it is not obvious when to use it (for me at least) and, in general, there seems to be no examples of ES6 modules in the documentation.

What to improve: Not a huge problem for me, but using modern JavaScript (not cutting edge, just anything that works since a couple of years) and, with that, make underscore optional? Many functional-style methods has been added to JavaScript arrays by now, so maybe this is sufficient? Similarly Map and Set might be helpful in some occasions. Reasons: Size and code-readability for people not familiar with underscore.

jashkenas commented 4 months ago

☝️ I endorse these suggested changes for a Backbone 2.0.

jgonggrijp commented 2 months ago

So far, we have one response, which only suggests evolutionary changes, rather than anything radical. Would it be safe to conclude that Backbone users just want the library to be updated with recent JavaScript and otherwise stay mostly the same? If anyone thinks otherwise, please don't hesitate to respond.

jdittrich commented 2 months ago

Not radical, either but:

jgonggrijp commented 2 months ago

@jdittrich

  • A standard way to manage child views might be great

A possible radical way to implement this, would be to unify Backbone.View with the custom elements standard. In that case, child views are managed by declaring them in the template HTML. Child views managed by the parent itself are in the custom element's shadow DOM, while child views inserted from the outside would go in a <slot>. I have an idea for a total redesign of the library that involves this change and others (still preserving MVC and loose coupling through events), but I've been holding off from sharing that idea because it would be a lot of work and I'm not sure people are waiting for it.

A possible non-radical way would be to absorb the core functionality from backbone-fractal into Backbone itself. That would probably amount to introducing a new CompositeView class. Such a feature could be added without a 2.0 release.

Yet another option is to just leave it to external libraries, as is currently the case. Marionette provides its own way to compose views, so how to do it in Backbone itself would probably be somewhat controversial.

  • I already pointed out that I would love a code update to ESM, ES6. In a similar vain: I wonder if code readability/learning/extending could be a focus in an update? That is not limited to code itself but also to documentation. It would not be a strong departure (though I find the event handling code difficult to understand sometimes) and might entail some potential compromizes where ease-of-understanding might be favored over performance, as well as architectural documentation (something between the line comments and the current documentation)

Could you elaborate a bit on how you would like to see this intermediate documentation? In any case, pure documentation changes are never breaking, so this could be done before a 2.0 update already.

Perhaps related: I have been wanting to deepen the indentation, which might already improve the readability. Such a change would best go together with a modularization, because that keeps all obfuscating changes in one batch.

jdittrich commented 2 months ago

intermediate documentation

…for me would usually involve

Basically, something that helps understanding how different parts of the code work together and how to read the code.

composite views

No strong opinion, for me the fractal integration sounds most meaningful.

jgonggrijp commented 2 months ago

@jdittrich I created a new issue (#4291) for your point about code understanding. It is a very good point and I think it does not need to (and perhaps should not) wait until the 2.0 release.

sgravrock commented 2 months ago

I haven't written any Backbone applications in ages, so take this with the appropriate amount of salt.

Change:

Keep:

markduncanawp commented 1 month ago

Backbone has saved us a lot of time and give us a clear starting point. Greatly appreciate your work!

paulfalgout commented 1 month ago

I would push back against adding view functionality.. Marionette's team at one point intended on dropping backbone as a strict dependency as extending the view to allow for other renders was difficult. A big ask had been dropping jQuery, and that meant making backbone optional. Making that easier would be good. In order to do it now it feels like a hack or just large copy-pastes from the backbone source. You can generally see those modifications here: https://github.com/marionettejs/backbone.marionette/pull/3679

Beyond that ESM would be great.. not sure if we've overcome the breaking issues of switching to class as far as how that changes patterns overall.

jgonggrijp commented 1 month ago

I would push back against adding view functionality..

For utmost clarity: which added functionality are you referring to here?

paulfalgout commented 1 month ago

absorb the core functionality from backbone-fractal in particular, but even the shadow DOM / custom elements.. backbone views should allow for that as a possibility without adding that as a required opinion.

jgonggrijp commented 1 month ago

@paulfalgout absorbing backbone-fractal would mean adding a new class (CompositeView) without changing anything about the original View base class. Would you still object to that?

The custom element thing is not so much a feature addition but a radical total redesign of the library. So far, I don't have the impression that a lot of people would want that.

paulfalgout commented 1 month ago

It adds opinion to the library handled by other 3rd party libraries that now may be expected to support the new stuff. It would make more sense to me if a significant portion of backbone users had already adopted it, but historically a light View layer opinion was characteristic of Backbone, and I'm not certain how at this point in time embedding a particular solution is any better than just saying "if you need to do X, here are a few options"