-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Discussion: Restructuring of Modules #859
Comments
It might make sense to have two distinct things: a name-space / code-organizing class, and a widget class. Naming I like Some possible properties: Shared properties Modules (code organizers) Components (widget things) |
What would the definition of a Module be? Proposed vs Current |
The post I made assumes that a module, currently, has two main functions as part of its definition: it is an object that can be used to namespace code, and it can be used to build a widget with. The proposed idea is to split these out into two separate things. @derickbailey proposed three separate things in this blog post (read: What's Next), and I'm sure he has a much better understanding of Marionette than I do, so perhaps it would even make sense to split it apart further. |
I use Modules in the sub-application context you're referring to, and for which the current pattern is well suited. I use them as lazy-loading sub-applications. I've made some tweaks to Marionette.Module so that Modules can declare dependencies on other modules - ie. I've rolled my own concept of
For my usage of components, they are not attached to the It absolutely makes sense that these should be extendable, and indeed I've often done so (ie. I think Component is a pretty well established term for collections of re-usable ui elements, and Module is equally well established when referring to large chunks of an application. To me Sub-Application for the latter and Modules for the former is a confusing break from what is, to my experience, pretty standard terminology. |
I totally agree with andru. I always think of "component" as some independent UI piece that can be added to any application. Like a small plug-in. And "module" as something that allows me to organize my code (it might not be related to UI at all). Other libraries are using the terms with those meanings (Polymer Project, ReactJS, etc). It's great to see the Marionette.Module growing (both here and in #792), but it's important to choose correct names. |
@andru I'd be interested to know more about how you are extending |
@andrewhubbs I warn you it's not the prettiest implementation, but it works... It's dependent on the asynchronous initializers in #792 https://gist.github.com/andru/8477224 |
Thanks @andru. I'll take a look. |
@jasonLaster and I had some good chats today about this topic. I realized when using the Module shortcut method to create a deeply-nested Module that it was applying my custom class to every parent module that it was creating. // If users and profiles don't exist, they will be instantiated as a SettingsModule
app.module( 'users.profiles.settings', {
moduleClass: SettingsModule
}); This is not documented per se, so it's difficult to say whether it's a bug or a feature of Modules. Either way, as @jasonLaster put it it's another nail in the coffin for Modules. For anonymous function Modules users, it's perfectly okay for the parents to be created on the fly. The modules themselves have no properties. But for Components this matters a lot! Every Component has (or should have) properties that are important. And the user should be the one to set this up; you shouldn't be able to just create a super-deeply nested component. We were throwing around the names Here's a quick gist showing possible API. I like the idea of a component/subcomponent distinction because it is a logical way to break up your apps. Components have certain powers, like communicating on the global channel (app.vent, and so on). Subcomponents, on the other hand, can't. They talk on their own local channel. This distinction would allow subcomponents to be instantiated with their parent's channel automatically. |
I've been following this issue and I'm with you on the need for a I can't tell from your gist: is this concept of a I don't think it's a good idea to mix this
The current implementation of Personally I've never use nested modules, so I can't comment on that aspect. My modules are non-reusable application level structures. |
@andru, great input, thanks! I'll respond more soon, but do you use the anonymous function or object literal definition for modules? Or both? If both, how do you decide when to use which? I'd like to get a feel for all the ways people use Modules to help us figure out the best way to break them up. |
@jmeas, thanks for revitalizing the discussing. I agree that distinguishing between components and namespaces is helpful. I'm a little bit hesitant about the component api you introduce. At work, we've been using module classes that look like this. There were a couple of reasons why we came to this design:
I realize, this is not your typical Marionette setup and is probably closer to a style of Modules as Controller design. @andru, I liked your examples for components. I also like how you distinguish between namespaces and application life-cyle (super insightful). When I think about this problem, I imagine building the google suite: mail, docs, chat. In this context, I think mail, docs, are modules that can be started and stopped. I see chat and parts of docs and mail as components. For example, chat is a component that's reused and lives inside the larger app. Similarily, a doc attached to an email can be modeled as a component. I'm glad we're having these discussions, because there are many use-cases for modules that I don't fully understand. I'd love some great examples where people rely on initializers, finalizers. Also, it'd be great to have a discussion about aysnc initializers. @andru, we use nested modules to describe sub-applications in a larger app. We're currently building a big inventory management app, which is a module that lives along-side, other apps. The inventory manager has several child modules: a quick edit module, bulk edit module, and several single purpose editors. Lastly, I'm worried about modules for several reasons:
|
I also find the design of the sub-module system very strange; there's no way for modules to share dependencies (unless they depend upon one-another, of course) and it seems counter-intuitive to traverse depth-first. This approach seems extremely limiting, but I cannot see the purpose of the limits. On the contrary, a proper dependency system could be hugely valuable to developers. I find the indexing of modules via magical strings strange as well, but it's similarly easy to ignore. One obvious use for Finally, I feel it's a mistake to have so many ways to customize modules when they are attached to the |
The v2 flag for this has been removed. This is quite a substantial change, so I think we should dedicate a version beyond v2, maybe v3, to just redoing Marionette architecture. |
Completely agree, I think the next step here is to create some best practice recipes for modules and then use their deficiencies to drive a better api. |
Modules are slated to be removed: ref #1321 |
Modules do a lot right now. They can be used for namespacing code and soon as UI/widget components.
There has been discussion about restructuring modules for version 2 of Marionette.
This issue can be used as a place of discussion for what needs to be done. Some questions:
// @cobbweb @samccone
TL;DR
I'm still unsure why @derickbailey suggested split them into more than 2 things, but the consensus of this conversation thus far has been that at least 2 things make sense.
Modules
for code organization;Components
for UI widgets.The text was updated successfully, but these errors were encountered: