bmorwood / chaos

a flex / flash to HTML5 boiler plate
0 stars 1 forks source link

use 'extend' instead of 'create' #4

Open bmorwood opened 10 years ago

bmorwood commented 10 years ago

Looking over a lot of frameworks, the convention seems to follow:

var ctrl = Chaos.Core.Controller.extend({

});

We could probably shorten this.. if we reserve the 'Chaos' namespace so that it just becomes.

Chaos.Controller.extend({});
Chaos.Presenter.extend({});
Chaos.Event.extend({});

I think I like that better.. again less to type. We can keep stuff organized in the Core folder, but then just make that assumption. 95% of everything will be in the core anyway.

For your own reference:

http://emberjs.com/

var component = Ember.Component.extend({});

http://backbonejs.org/#Model

var model = Backbone.Model.extend({});

https://github.com/EventedMind/iron-router

var controller = RouteController.extend({});
bmorwood commented 10 years ago

so would we just have two the two methods? register() for events, makes sense to me and extend for anything you are adding to your class a prototype? what about create() for anything you want to create a new new instance of and not extend? or would you just use the 'new' statement?

xpressivecode commented 10 years ago

I'm not sure. I think we play it by ear. If we find we have the need for a feature or method we could look at implementing it then. Hopefully at that time, enough of the API will have been flushed out that we'll know exactly how to implement it. Or at the very least, have a better idea of which direction we're taking.

Maybe for something like

new myapp.events.BlahEvent(myapp.Events.BlahEvent.OPEN).emit();

we use

myapp.events.emit(myapp.events.BlahEvent.OPEN);

or

myapp.events.BlahEvent.emit('OPEN');

we can have an emit on the static class and have it do the create or what have you behind the scenes. It's cleaner (user doesn't have to worry about clean up or instantiation).