Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Remove references of third-party libraries on cilantro object
Browse files Browse the repository at this point in the history
This is to improve clarity of the code as well as make it possible
to load the individual third-party modules for use in the project or
override the core libraries if existing in a project.

The dropped references include:

- `c.$`
- `c._`
- `c.Backbone`
- `c.Marionette`
- `c.Highcharts`

These dependencies must now be included explicitly in the dependencies
array for the module.

In addition, the subscribe/publish hooks for Marionette.ItemView have
been removed. There were only two areas this was being used and they
were simply replaced with `c.mediator`.
  • Loading branch information
bruth committed Sep 15, 2013
1 parent 3f9d6e8 commit 12cf276
Show file tree
Hide file tree
Showing 76 changed files with 494 additions and 473 deletions.
4 changes: 2 additions & 2 deletions spec/ControlSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(['cilantro', 'text!/mock/fields.json'], function (c, fieldsJSON) {
var fields = new c.Backbone.Collection(JSON.parse(fieldsJSON));
define(['backbone', 'cilantro', 'text!/mock/fields.json'], function (Backbone, c, fieldsJSON) {
var fields = new Backbone.Collection(JSON.parse(fieldsJSON));

describe('FieldControl', function() {
var control;
Expand Down
50 changes: 25 additions & 25 deletions spec/RouterSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['cilantro'], function(c) {
define(['jquery', 'underscore', 'backbone', 'cilantro'], function($, _, Backbone, c) {

var routes;

Expand All @@ -8,7 +8,7 @@ define(['cilantro'], function(c) {
routes = [{
id: 1,
route: 'foo/',
view: new c.Backbone.View,
view: new Backbone.View,
el: '#region1'
}, {
id: 2,
Expand All @@ -18,7 +18,7 @@ define(['cilantro'], function(c) {
}, {
id: 3,
route: 'foo/',
view: new c.Backbone.View,
view: new Backbone.View,
el: '#region3'
}, {
id: 4,
Expand All @@ -27,24 +27,24 @@ define(['cilantro'], function(c) {
el: '#region3'
}];

c.$('#region1, #region2, #region3').remove();
$('#region1, #region2, #region3').remove();

c.$('body')
$('body')
.append('<div id=region1 />')
.append('<div id=region2 />')
.append('<div id=region3 />');

c.router.options.el = 'body';
c.router.register(routes);
c.Backbone.history.start({pushState: false, hashChange: true});
Backbone.history.start({pushState: false, hashChange: true});
});

afterEach(function() {
c.Backbone.history.navigate();
c.Backbone.history.stop();
c.Backbone.history.handlers = [];
Backbone.history.navigate();
Backbone.history.stop();
Backbone.history.handlers = [];

c._.each(c._.keys(c.router._registered), function(id) {
_.each(_.keys(c.router._registered), function(id) {
c.router.unregister(id);
});
c.router._handlers = {};
Expand All @@ -53,21 +53,21 @@ define(['cilantro'], function(c) {
describe('Register', function() {

it('should register', function() {
expect(c._.keys(c.router._registered).length).toEqual(4);
expect(_.keys(c.router._registered).length).toEqual(4);
expect(c.router._loaded.length).toEqual(0);
expect(c._.keys(c.router._handlers).length).toEqual(2);
expect(c._.keys(c.router._routes).length).toEqual(2);
expect(_.keys(c.router._handlers).length).toEqual(2);
expect(_.keys(c.router._routes).length).toEqual(2);
});

it('should load non-route routes on register', function() {
c.router.register({
id: 5,
view: new Backbone.View
});
expect(c._.keys(c.router._registered).length).toEqual(5);
expect(_.keys(c.router._registered).length).toEqual(5);
expect(c.router._loaded.length).toEqual(1);
expect(c._.keys(c.router._handlers).length).toEqual(2);
expect(c._.keys(c.router._routes).length).toEqual(2);
expect(_.keys(c.router._handlers).length).toEqual(2);
expect(_.keys(c.router._routes).length).toEqual(2);
});
});

Expand All @@ -76,7 +76,7 @@ define(['cilantro'], function(c) {
it('should unregister', function() {
c.router.unregister(routes[0].id);

expect(c._.keys(c.router._registered).length).toEqual(3);
expect(_.keys(c.router._registered).length).toEqual(3);
expect(c.router._loaded.length).toEqual(0);
});

Expand All @@ -86,12 +86,12 @@ define(['cilantro'], function(c) {
view: new Backbone.View
});

expect(c._.keys(c.router._registered).length).toEqual(5);
expect(_.keys(c.router._registered).length).toEqual(5);
expect(c.router._loaded.length).toEqual(1);

c.router.unregister(5);

expect(c._.keys(c.router._registered).length).toEqual(4);
expect(_.keys(c.router._registered).length).toEqual(4);
expect(c.router._loaded.length).toEqual(0);
});

Expand All @@ -100,7 +100,7 @@ define(['cilantro'], function(c) {
describe('Routing', function() {

it('should load views', function() {
expect(c.Backbone.history.navigate('foo/', {trigger: true})).toBe(true);
expect(Backbone.history.navigate('foo/', {trigger: true})).toBe(true);

// First two are loaded immediately since they are local views
expect(c.router._loaded.length).toEqual(2);
Expand All @@ -116,13 +116,13 @@ define(['cilantro'], function(c) {
});

it('should unload loaded modules', function() {
expect(c.Backbone.history.navigate('bar/', {trigger: true})).toBe(true);
expect(Backbone.history.navigate('bar/', {trigger: true})).toBe(true);
expect(c.router._loaded.length).toEqual(1);

children = $('#region3').children();
expect(children.length).toEqual(1);

expect(c.Backbone.history.navigate('foo/', {trigger: true})).toBe(true);
expect(Backbone.history.navigate('foo/', {trigger: true})).toBe(true);

// New element is added, but only the new one is visible
children = $('#region3').children();
Expand Down Expand Up @@ -152,13 +152,13 @@ define(['cilantro'], function(c) {
});

it('should trigger the load event', function() {
c.Backbone.history.navigate('foo/', {trigger: true});
Backbone.history.navigate('foo/', {trigger: true});
expect(loaded).toBe(true);
});

it('should trigger the unload event', function() {
c.Backbone.history.navigate('foo/', {trigger: true});
c.Backbone.history.navigate('bar/', {trigger: true});
Backbone.history.navigate('foo/', {trigger: true});
Backbone.history.navigate('bar/', {trigger: true});
expect(loaded).toBe(false);
});
});
Expand Down
4 changes: 2 additions & 2 deletions spec/route-spec-mod.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
define(['cilantro'], function(c) {
return c.Backbone.View;
define(['backbone'], function(Backbone) {
return Backbone.View;
});
13 changes: 3 additions & 10 deletions src/coffee/cilantro/core.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
define [
'jquery'
'underscore'
'backbone'
'mediator'
'promiser'
'loglevel'
Expand All @@ -16,7 +14,7 @@ define [
# Note, these are applied in place.
'plugins/js'
'plugins/jquery-ajax-queue'
], ($, _, Backbone, mediator, promiser, loglevel, config, channels, utils, session, changelog) ->
], (_, mediator, promiser, loglevel, config, channels, utils, session, changelog) ->

c =
# Version of cilantro
Expand Down Expand Up @@ -72,10 +70,5 @@ define [
# Mediator channel topics for communication across the application
channels = _.extend {}, channels, session.channels

# Additional properties to attach
# [DEPRECATED: 2.1.0] Require core libraries directly
props = { $, _, Backbone }

# Construct the base object which is composed core libraries, the
# mediator methods, session manager, and the config object
_.extend c, mediator, channels, props
# Mixin various components
_.extend c, mediator, channels
6 changes: 3 additions & 3 deletions src/coffee/cilantro/models.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define [
'./core'
'underscore'
'./models/field'
'./models/concept'
'./models/context'
Expand All @@ -9,6 +9,6 @@ define [
'./models/exporter'
'./models/query'
'./models/value'
], (c, mods...) ->
], (_, mods...) ->

c._.extend {}, mods...
_.extend {}, mods...
8 changes: 4 additions & 4 deletions src/coffee/cilantro/models/base.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
define [
'../core'
], (c) ->
'backbone'
], (Backbone) ->

class Model extends c.Backbone.Model
class Model extends Backbone.Model
url: ->
if @isNew() then super else @links.self

Expand All @@ -18,7 +18,7 @@ define [
return attrs


class Collection extends c.Backbone.Collection
class Collection extends Backbone.Collection
model: Model

url: ->
Expand Down
15 changes: 9 additions & 6 deletions src/coffee/cilantro/models/concept.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
define [
'../core'
'./base'
'./field'
], (c, base, field) ->
'jquery'
'underscore'
'backbone'
'../core'
'./base'
'./field'
], ($, _, Backbone, c, base, field) ->


class ConceptModel extends base.Model
Expand Down Expand Up @@ -37,8 +40,8 @@ define [
c.session.url('concepts')

search: (query, handler) ->
c.$.ajax
url: c._.result @, 'url'
$.ajax
url: _.result @, 'url'
data: query: query, brief: 1
dataType: 'json'
success: (resp) -> handler(resp)
Expand Down
6 changes: 3 additions & 3 deletions src/coffee/cilantro/models/context.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
define [
'../core'
'underscore'
'./context/nodes'
'./context/model'
], (c, mods...) ->
], (_, mods...) ->

c._.extend {}, mods...
_.extend {}, mods...
21 changes: 11 additions & 10 deletions src/coffee/cilantro/models/context/manager.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
define [
'../../core'
'underscore'
'backbone'
'./nodes'
], (c, nodes) ->
], (_, Backbone, nodes) ->

class Events

c._.extend Events::, c.Backbone.Events
_.extend Events::, Backbone.Events


# Light wrapper for fixing attrs for the top-level branch node. If `attrs`
Expand All @@ -30,7 +31,7 @@ define [
'change:enabled': 'save'

constructor: (@model, options) ->
@options = c._.extend({}, @options, options)
@options = _.extend({}, @options, options)

# Define the working and upstream trees
@working = new nodes.BranchNodeModel null,
Expand Down Expand Up @@ -76,7 +77,7 @@ define [
# later if more complex tree layouts are used.
return @_toJSON(node, options)

attrs = c._.clone(node.attributes)
attrs = _.clone(node.attributes)

if node.type is 'branch'
children = []
Expand Down Expand Up @@ -104,7 +105,7 @@ define [
update: (attrs) ->
# Ensure the active and working trees are not empty, otherwise
# change events do not fire.
attrs = c._.extend
attrs = _.extend
children: []
type: 'and'
, attrs
Expand Down Expand Up @@ -135,11 +136,11 @@ define [
# Define a node in the tree. Takes an option `type` which specifies
# the node type to create.
define: (attrs, path, options) ->
if not c._.isArray(path)
if not _.isArray(path)
options = path
path = []

options = c._.extend
options = _.extend
identKeys: @options.identKeys
, options

Expand All @@ -157,15 +158,15 @@ define [

# Get the identity of this node and add it to the parent
parent.children.add(attrs, options)
return @find(c._.pick(attrs, options.identKeys))
return @find(_.pick(attrs, options.identKeys))

# Save the model on behalf of a node.
# TODO this assumes only a single node has been changed. If multiple
# nodes are changed, only the node that triggers causes the save will
# have it's events triggered.
save: (node, options) ->
# Trigger 'request' on node
options = c._.extend {}, options,
options = _.extend {}, options,
beforeSend: (xhr) =>
node.trigger('request', node, xhr, options)

Expand Down
6 changes: 3 additions & 3 deletions src/coffee/cilantro/models/context/nodes.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
define [
'../../core'
'underscore'
'./nodes/base'
'./nodes/condition'
'./nodes/branch'
'./nodes/composite'
], (c, mods...) ->
], (_, mods...) ->

c._.extend {}, mods...
_.extend {}, mods...

0 comments on commit 12cf276

Please sign in to comment.