Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 25 additions & 59 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,8 @@ banner = """
* For all details and documentation:
* http://chaplinjs.org
*/

"""

umdHead = '''
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['backbone', 'underscore'], factory);
} else if (typeof module === 'object' && module && module.exports) {
module.exports = factory(require('backbone'), require('underscore'));
} else if (typeof require === 'function') {
factory(window.Backbone, window._ || window.Backbone.utils);
} else {
throw new Error('Chaplin requires Common.js or AMD modules');
}
}(this, function(Backbone, _) {
function require(name) {
return {backbone: Backbone, underscore: _}[name];
}

require =
'''

umdTail = '''
return require(1);
}))
'''

setupJSDOM = ->
require('jsdom-global')(undefined,
url: 'https://github.com'
Expand Down Expand Up @@ -72,7 +47,6 @@ module.exports = (grunt) ->
reporter: 'spec'
require: [
'coffee-script/register'
'coffee-coverage/register-istanbul'
setupJSDOM
-> require.cache[require.resolve 'jquery'] = {}
'backbone.nativeview'
Expand All @@ -90,37 +64,33 @@ module.exports = (grunt) ->
]
src: 'test/*.coffee'

makeReport:
src: 'coverage/coverage-coffee.json',
options:
type: 'html'
dir: 'coverage'
rollup:
options: {
plugins: [
require('rollup-plugin-coffee-script')()
require('rollup-plugin-node-resolve')(extensions: ['.coffee'])
]
external: [
'underscore'
'backbone'
]
globals:
underscore: '_'
backbone: 'Backbone'
format: 'umd'
moduleName: 'Chaplin'
intro: '_ = _ || Backbone.utils;' # support exoskeleton
banner
}

browserify:
dist:
files:
'build/chaplin.js': ['./src/chaplin.coffee']
options: {
banner
external: ['backbone', 'underscore']
transform: ['coffeeify']
browserifyOptions:
debug: true
extensions: ['.coffee']
postBundleCB: (err, src, next) ->
if err
next err
else
src = umdHead + src + umdTail
next null, new Buffer src
}
'build/chaplin.js': 'src/chaplin.coffee'

# Minify
# ======
uglify:
options:
mangle: true
universal:
dist:
files:
'build/chaplin.min.js': 'build/chaplin.js'

Expand Down Expand Up @@ -234,8 +204,8 @@ module.exports = (grunt) ->
grunt.log.ok()

grunt.registerTask 'check:versions', [
'check:versions:component',
'check:versions:changelog',
'check:versions:component'
'check:versions:changelog'
'check:versions:docs'
]

Expand Down Expand Up @@ -312,16 +282,12 @@ module.exports = (grunt) ->
# Tests
# =====
grunt.registerTask 'lint', 'coffeelint'
grunt.registerTask 'test', 'mochaTest:native'
grunt.registerTask 'test:jquery', 'mochaTest:jquery'

# Coverage
# ========
grunt.registerTask 'coverage', ['mochaTest:native', 'makeReport']
grunt.registerTask 'test', ['rollup', 'mochaTest:native']
grunt.registerTask 'test:jquery', ['rollup', 'mochaTest:jquery']

# Building
# ========
grunt.registerTask 'build', ['browserify', 'uglify', 'compress']
grunt.registerTask 'build', ['rollup', 'uglify', 'compress']

# Default
# =======
Expand Down
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,25 @@
"devDependencies": {
"backbone.nativeview": "~0.3.3",
"chai": "~4.1.1",
"coffee-coverage": "1.0.1",
"coffee-script": "~1.12.7",
"coffeeify": "~2.0.1",
"grunt": "~0.4.5",
"grunt-browserify": "~4.0.1",
"grunt-cli": "~0.1.13",
"grunt-coffeelint": "~0.0.15",
"grunt-contrib-compress": "0.14.x",
"grunt-contrib-uglify": "~0.11.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-istanbul": "0.7.0",
"grunt": "~1.0.1",
"grunt-cli": "~1.2.0",
"grunt-coffeelint": "~0.0.16",
"grunt-contrib-compress": "~1.4.3",
"grunt-contrib-uglify": "~3.0.1",
"grunt-contrib-watch": "~1.0.0",
"grunt-mocha-test": "~0.13.2",
"grunt-transbrute": "0.2.x",
"jquery": "2.2.x",
"jsdom": "~11.1.0",
"grunt-rollup": "~5.0.0",
"grunt-transbrute": "~1.0.1",
"jquery": "~2.2.0",
"jsdom": "~11.2.0",
"jsdom-global": "~3.0.2",
"mocha": "~3.5.0",
"prompt": "~0.2.14",
"sinon": "~2.3.6",
"sinon-chai": "~2.12.0"
"rollup-plugin-coffee-script": "~1.1.0",
"rollup-plugin-node-resolve": "~3.0.0",
"sinon": "~3.2.1",
"sinon-chai": "~2.13.0"
},
"main": "build/chaplin.js",
"scripts": {
Expand Down
58 changes: 38 additions & 20 deletions src/chaplin.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
'use strict'
import Application from './chaplin/application'
import Composer from './chaplin/composer'
import Controller from './chaplin/controllers/controller'
import Dispatcher from './chaplin/dispatcher'
import Composition from './chaplin/lib/composition'
import EventBroker from './chaplin/lib/event_broker'
import History from './chaplin/lib/history'
import Route from './chaplin/lib/route'
import Router from './chaplin/lib/router'
import support from './chaplin/lib/support'
import SyncMachine from './chaplin/lib/sync_machine'
import utils from './chaplin/lib/utils'
import mediator from './chaplin/mediator'
import Collection from './chaplin/models/collection'
import Model from './chaplin/models/model'
import CollectionView from './chaplin/views/collection_view'
import Layout from './chaplin/views/layout'
import View from './chaplin/views/view'

# Main entry point into Chaplin module.
# Load all components and expose them.
module.exports =
Application: require './chaplin/application'
Composer: require './chaplin/composer'
Controller: require './chaplin/controllers/controller'
Dispatcher: require './chaplin/dispatcher'
Composition: require './chaplin/lib/composition'
EventBroker: require './chaplin/lib/event_broker'
History: require './chaplin/lib/history'
Route: require './chaplin/lib/route'
Router: require './chaplin/lib/router'
support: require './chaplin/lib/support'
SyncMachine: require './chaplin/lib/sync_machine'
utils: require './chaplin/lib/utils'
mediator: require './chaplin/mediator'
Collection: require './chaplin/models/collection'
Model: require './chaplin/models/model'
CollectionView: require './chaplin/views/collection_view'
Layout: require './chaplin/views/layout'
View: require './chaplin/views/view'
export default {
Application
Composer
Controller
Dispatcher
Composition
EventBroker
History
Route
Router
support
SyncMachine
utils
mediator
Collection
Model
CollectionView
Layout
View
}
22 changes: 11 additions & 11 deletions src/chaplin/application.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
'use strict'

# Third-party libraries.
_ = require 'underscore'
Backbone = require 'backbone'
import _ from 'underscore'
import Backbone from 'backbone'

# CoffeeScript classes which are instantiated with `new`
Composer = require './composer'
Dispatcher = require './dispatcher'
Router = require './lib/router'
Layout = require './views/layout'
import Composer from './composer'
import Dispatcher from './dispatcher'
import Router from './lib/router'
import Layout from './views/layout'

# A mix-in that should be mixed to class.
EventBroker = require './lib/event_broker'
import EventBroker from './lib/event_broker'

# Independent global event bus that is used by itself, so lowercased.
mediator = require './mediator'
import mediator from './mediator'

# The bootstrapper is the entry point for Chaplin apps.
module.exports = class Application
export default class Application
# Borrow the `extend` method from a dear friend.
@extend = Backbone.Model.extend

Expand Down Expand Up @@ -130,6 +128,8 @@ module.exports = class Application
# Seal the application instance to prevent further changes.
Object.seal this

disposed: false

dispose: ->
# Am I already disposed?
return if @disposed
Expand Down
14 changes: 6 additions & 8 deletions src/chaplin/composer.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'

Composition = require './lib/composition'
EventBroker = require './lib/event_broker'
mediator = require './mediator'
import Composition from './lib/composition'
import EventBroker from './lib/event_broker'
import mediator from './mediator'

# Composer
# --------
Expand All @@ -18,7 +16,7 @@ mediator = require './mediator'
# is routed to where a view that was composed is not re-composed, the
# composed view is disposed.

module.exports = class Composer
export default class Composer
# Borrow the static extend method from Backbone
@extend = Backbone.Model.extend

Expand Down
14 changes: 6 additions & 8 deletions src/chaplin/controllers/controller.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'
import mediator from '../mediator'
import EventBroker from '../lib/event_broker'
import utils from '../lib/utils'

mediator = require '../mediator'
EventBroker = require '../lib/event_broker'
utils = require '../lib/utils'

module.exports = class Controller
export default class Controller
# Borrow the static extend method from Backbone.
@extend = Backbone.Model.extend

Expand Down
14 changes: 6 additions & 8 deletions src/chaplin/dispatcher.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'
import EventBroker from './lib/event_broker'
import utils from './lib/utils'
import mediator from './mediator'

EventBroker = require './lib/event_broker'
utils = require './lib/utils'
mediator = require './mediator'

module.exports = class Dispatcher
export default class Dispatcher
# Borrow the static extend method from Backbone.
@extend = Backbone.Model.extend

Expand Down
9 changes: 4 additions & 5 deletions src/chaplin/lib/composition.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'
EventBroker = require './event_broker'
import EventBroker from './event_broker'

# Composition
# -----------
Expand All @@ -11,7 +10,7 @@ EventBroker = require './event_broker'
# controller that is used internally to inflate simple
# calls to !composer:compose and may be extended and used to have complete
# control over the composition process.
module.exports = class Composition
export default class Composition
# Borrow the static extend method from Backbone.
@extend = Backbone.Model.extend

Expand Down
12 changes: 2 additions & 10 deletions src/chaplin/lib/event_broker.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

mediator = require '../mediator'
import mediator from '../mediator'

# Add functionality to subscribe and publish to global
# Publish/Subscribe events so they can be removed afterwards
Expand All @@ -14,7 +12,7 @@ mediator = require '../mediator'
# Since Backbone 0.9.2 this abstraction just serves the purpose
# that a handler cannot be registered twice for the same event.

EventBroker =
export default Object.freeze
subscribeEvent: (type, handler) ->
if typeof type isnt 'string'
throw new TypeError 'EventBroker#subscribeEvent: ' +
Expand Down Expand Up @@ -66,9 +64,3 @@ EventBroker =

# Publish global handler.
mediator.publish type, args...

# You’re frozen when your heart’s not open.
Object.freeze EventBroker

# Return our creation.
module.exports = EventBroker
Loading