Finally got the demo view working (mostly). Need to turn off third party ajax requests.

This commit is contained in:
Scott Erickson 2014-06-14 15:02:14 -07:00
parent 1013f52c14
commit 4932317982
4 changed files with 17 additions and 8 deletions

View file

@ -2,7 +2,7 @@ CocoView = require 'views/kinds/CocoView'
template = require 'templates/demo'
requireUtils = require 'lib/requireUtils'
DEMO_REQUIRE_PREFIX = 'demo/app/'
DEMO_REQUIRE_PREFIX = 'test/demo/'
DEMO_URL_PREFIX = '/demo/'
###
@ -37,7 +37,8 @@ module.exports = DemoView = class DemoView extends CocoView
loadDemoingLibs: ->
@queue = new createjs.LoadQueue()
@queue.on('complete', @scriptsLoaded, @)
for f in ['jasmine', 'jasmine-html', 'boot', 'mock-ajax', 'demo-app']
window.jasmine = {} # so that mock-ajax properly loads. It expects jasmine to be loaded
for f in ['mock-ajax', 'demo-app']
@queue.loadFile({
src: "/javascripts/#{f}.js"
type: createjs.LoadQueue.JAVASCRIPT
@ -64,7 +65,7 @@ module.exports = DemoView = class DemoView extends CocoView
initDemoFiles: ->
@demoFiles = @getAllDemoFiles()
if @subPath
prefix = TEST_REQUIRE_PREFIX + @subPath
prefix = DEMO_REQUIRE_PREFIX + @subPath
@demoFiles = (f for f in @demoFiles when f.startsWith prefix)
runDemo: ->
@ -75,11 +76,13 @@ module.exports = DemoView = class DemoView extends CocoView
if not _.isFunction(demoFunc)
console.error "Demo files must export a function. #{requirePath} does not."
return
jasmine.Ajax.install()
view = demoFunc()
return unless view
@$el.find('#demo-area').empty().append(view.el)
@$el.find('#demo-area').empty().append(view.$el)
# TODO, maybe handle root views differently than modal views differently than everything else?
getAllDemoFiles = ->
getAllDemoFiles: ->
allFiles = window.require.list()
(f for f in allFiles when f.indexOf('.demo') > -1)

View file

@ -5,7 +5,6 @@ startsWith = (string, substring) ->
exports.config =
paths:
'public': 'public'
'watched': ['app', 'test', 'vendor', 'demo', 'bower_components']
conventions:
ignored: (path) -> startsWith(sysPath.basename(path), '_')
sourceMaps: true
@ -36,7 +35,7 @@ exports.config =
(bower_components[\/\\]aether[\/\\]build[\/\\]aether.js)
)///
'javascripts/test-app.js': /^test[\/\\]app/
'javascripts/demo-app.js': /^demo/
'javascripts/demo-app.js': /^test[\/\\]demo/
order:
before: [

View file

@ -17,5 +17,12 @@ class BlandModel extends CocoModel
module.exports = ->
model = new BlandModel({_id:'12345'})
new PatchesView(model)
v = new PatchesView(model)
v.load()
# doesn't quite work yet. Intercepts a mixpanel request instead
r = jasmine.Ajax.requests.mostRecent()
r.send({statusCode:200, responseText:"[]"})
v.render()
v