Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Further Development #9

Closed
wants to merge 140 commits into from
Closed

Further Development #9

wants to merge 140 commits into from

Conversation

molily
Copy link
Member

@molily molily commented Mar 8, 2012

I made some changes on the core architecture as well as smaller changes and bundled them in this branch to discuss about them.

The most important thing is probably the split of the controller startup/disposal logic between ApplicationController and ApplicationView. I always felt that ApplicationView isn’t the right place since it’s not a view question, but a app-wide mechanism. ApplicationController as parent of other controllers makes more sense.

Second thing is the split between Router and routes. The routes used to lie in the Router class which is definitely not the right place. Now they are sourced out into a routes.coffee which looks much like the Rails counterpart routes.rb.

Third thing is the mediator revamp. mediator.user is now readonly in ES5-conformant browsers and the new mediator.setUser method should be used when setting the user. The idea is to prevent accidental overwriting. At least you will get a strict mode exception in ES5-capable browsers.

What do you think?

…Controller.

Let them communicate via Pub/Sub. AppView is responsible for all view changes
while the AppController is responsible for startup and disposal of controllers.
Use mediator.setUser to write the user.
This should avoid accidental overwriting while allowing to read the user easily.
Don’t know yet if that is necessary or a good solution.
Properly test for ES5 support.
@paulmillr
Copy link
Contributor

Why console.debug statements has been removed? They're pretty useful. Or they're not needed in the new version?

require ['controllers/' + controllerFileName], handler

# Handler for the controller lazy-loading
controllerLoaded: (controllerName, action, params, ControllerConstructor) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent refactor. This movement is correct, application_view was doing things that usually the app controller should do.

So, following a common App Controller pattern, I think this method should be called execute().

@molily
Copy link
Member Author

molily commented Mar 9, 2012

Don’t like the idea of having user on the mediator either. But I cannot think of a solution which ensures that the user is globally and easily accessible.

A mediator doesn’t have to be limited to Pub/Sub in my opinion, the mediator object might also store data which might be shared between modules.

Of course we could have, for example, a session module with a user property. This would be better in regard to separation of concerns, but wouldn’t improve anything beyong that. It would just introduce another mediator-like object.

Since the user might change during the lifetime of a module, mixing in the user won’t help. While controller are volatile, mostly models and views are dealing with the user and have to react on changes.

I like the current mediator concept because it’s dead simple. Some central—data like the user—is shared on the mediator, the rest of the data may be shared using the mediator’s Pub/Sub mechanism (or by introducing additional special-purpose mediators). So most modules already include the mediator and can access the user.

Ideally there should be a user module which can be included and referencing it should yield a the current user object. But that’s not possible in ECMAScript at the moment. It could be a function instead, then you would have to write user().

@Rendez
Copy link
Contributor

Rendez commented Mar 9, 2012

What I was suggesting is that controllers receive the user instance, so they can also handle it to their views on initialization.
The user instance is stored in session, which is part of ApplicationController, which is the one instantiating new modules/controllers now.

@molily
Copy link
Member Author

molily commented Mar 9, 2012

Sure, but the user may change during the lifetime of a module. I don’t see the advantage of passing the user from AppController down to models and views and save it there. The user might be null on controller startup or an object which might get stale when logout occurs. So each module needs to fetch a fresh instance with every access anyway, so there has to be a global way to achieve that. An option would be that each module maintains a @user property and automatically updates it on initialize, login and logout.

…l be an exception anyway. Controller#dispose is always defined by controller.coffee.
@Rendez
Copy link
Contributor

Rendez commented Mar 9, 2012

Yeah. The only way is to not store the user and initialize everything passing the user as argument, and then rely on mediator.subscribe 'login' as usual.

In the example collections, overwrite the fetch method and use that. Properly reset the collections on logout.
@molily
Copy link
Member Author

molily commented Mar 9, 2012

@paulmillr The excessive debug output was used during development and bugfixing. They are fine for this purpose. But for someone who’s reading and reusing the code, they are useless and just pollute the code. Sometimes they need to be replacing by better comments.

It seems to be valuable for some people. I’ll remove detailed debug output soon
but leave the interesting console calls intact (initialize, render and so on).

This reverts commit 9a35ffe.

Conflicts:

	coffee/models/likes.coffee
	coffee/models/posts.coffee
@paulmillr
Copy link
Contributor

Cool. Is this going to be stable soon (I want to include it to brunch 1.0)?

@molily
Copy link
Member Author

molily commented Mar 14, 2012

@paulmillr Sure, I’ll hope I can polish this up this next week.

As a next step, I’d like to add a concept of persisting controllers (see issue #4). I think this is a important feature and we should at least provide a standard solution.

Conflicts:
	coffee/lib/router.coffee
@molily
Copy link
Member Author

molily commented Mar 14, 2012

Thanks for the input, @cpsubrian, these are good ideas. I’ve read an article on the Rails logging today (http://www.paperplanes.de/2012/3/14/on-notifications-logsubscribers-and-bringing-sanity-to-rails-logging.html) and I agree with you that a Pub/Sub-based logging approach could help. I will also have to look at the socket.io logging you’ve mentioned.

molily and others added 16 commits April 25, 2012 01:50
This will preserve comments in js source.

Closes #30.
Collection: Improved the inserting algorithm so all items views are inserted after the non-view elements
Conflicts:
	coffee/chaplin/views/collection_view.coffee
	js/chaplin/views/collection_view.js
- Standardize debug messages
- Style: Replaced some standalone `@` with `this`
@molily molily closed this Apr 27, 2012
molily and others added 9 commits April 28, 2012 00:45
Changed the README to reflect the current development
CollectionView: Remove unused method collectionIsSynced
…g DOM event handlers declaratively works again
- Remove duplicate call of getLoginStatus after loginAbort
- Correctly pass the loginContext to loginStatusAfterAbort (fixes an exception when aborting the login)
- Rename facebook_commment event to facebook:comment
- Remove postToStream, you should not do this
- Delete status and accessToken on disposal
- Optimize event payload object
@paulmillr paulmillr reopened this May 2, 2012
@paulmillr
Copy link
Contributor

@molily lets merge this to master. dev branch is stable and we're not pushing new release anyway.

@paulmillr
Copy link
Contributor

because it can't be automatically merged, how about a simple renaming of branches?

@paulmillr paulmillr closed this May 2, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants