GeppettoJS / backbone.geppetto

Bring your Backbone applications to life with an event-driven Command framework.
http://geppettojs.github.com/backbone.geppetto/
MIT License
203 stars 28 forks source link

Declare Context wiring configs in external files #35

Closed geekdave closed 10 years ago

geekdave commented 11 years ago

Would be nice to externalize the wiring like so:

using a single wiringConfig file

src/user/UserContext.js

define([
  "geppetto",
  "src/user/wiringConfig.js"
], function(
  Geppetto,
  wiringConfig
) {
  return Geppetto.Context.extend({
    wiring: wiringConfig
  });
});

src/user/wiringConfig.js

define([
  "src/users/commands/FooCommand.js",
  "src/users/commands/BarCommand.js",
  "src/users/foo.js",
  "src/users/qux.js"
], function( 
  FooCommand,
  BarCommand,
  Foo,
  Qux
) {
  return {
    commands: {
        "appEventFoo":          FooCommand,
        "appEventFooBarBaz":   FooCommand
    },
    singletons: {
        foo: Foo
    },
    classes :{
        bar: Bar
    },
    values : {
        someValue: 10
    },
    views: {
        qux : Qux
    }
  }
});

using multiple config files

src/user/UserContext.js

define([
  "geppetto",
  "src/user/wiring/commands.js",
  "src/user/wiring/singletons.js",
  "src/user/wiring/classes.js",
  "src/user/wiring/values.js",
  "src/user/wiring/views.js"
], function(
  Geppetto,
  commandsConfig,
  singletonsConfig,
  classesConfig,
  valuesConfig,
  viewsConfig
) {
  return Geppetto.Context.extend({
    wiring: {
        commands: commandsConfig,
        singletons: singletonsConfig,
        classes: classesConfig,
        values: valuesConfig,
        views: viewsConfig
    }
  });
});

src/user/wiring/commands.js

define([
  "src/users/commands/FooCommand.js",
  "src/users/commands/BarCommand.js"
], function(
  FooCommand,
  BarCommand
) {
  return {
        "appEventFoo":          FooCommand,
        "appEventFooBarBaz":   BarCommand
  }
});

src/user/wiring/singletons.js

define([
  "src/users/foo.js"
], function(
  Foo
) {
  return {
        foo: Foo
  }
});
geekdave commented 10 years ago

I just tested, and this is already possible using the above examples. It's just plain ol' RequireJS functionality, with no special Geppetto features necessary. Closing.