hasChangedSignificantly async refactor

Still checking for bugs
This commit is contained in:
Michael Schmatz 2014-04-22 08:54:35 -07:00
parent 0f435b41ae
commit 81809956b8
6 changed files with 1118 additions and 52 deletions

View file

@ -74,7 +74,12 @@ module.exports = class CastButtonView extends View
updateCastButton: ->
return if _.some @spells, (spell) => not spell.loaded
castable = _.some @spells, (spell) => spell.hasChangedSignificantly spell.getSource()
#this is going to have some problems...
async.some _.values(@spells), (spell, callback) =>
spell.hasChangedSignificantly spell.getSource(), null, callback
, (castable) =>
console.log "Castable is #{castable}"
@castButtonGroup.toggleClass('castable', castable).toggleClass('casting', @casting)
if @casting
s = $.i18n.t("play_level.tome_cast_button_casting", defaultValue: "Casting")

View file

@ -88,14 +88,26 @@ module.exports = class Spell
hasChanged: (newSource=null, currentSource=null) ->
(newSource ? @originalSource) isnt (currentSource ? @source)
hasChangedSignificantly: (newSource=null, currentSource=null) ->
hasChangedSignificantly: (newSource=null, currentSource=null, cb) ->
for thangID, spellThang of @thangs
aether = spellThang.aether
break
unless aether
console.error @toString(), "couldn't find a spellThang with aether of", @thangs
return false
aether.hasChangedSignificantly (newSource ? @originalSource), (currentSource ? @source), true, true
workerMessage =
function: "hasChangedSignificantly"
a: (newSource ? @originalSource)
spellKey: @spellKey
b: (currentSource ? @source)
careAboutLineNumbers: true
careAboutLint: true
@worker.addEventListener "message", (e) =>
workerData = JSON.parse e.data
if workerData.function is "hasChangedSignificantly"
@worker.removeEventListener("message",arguments.callee, false)
cb(workerData.hasChanged)
@worker.postMessage JSON.stringify(workerMessage)
createAether: (thang) ->
aceConfig = me.get('aceConfig') ? {}

View file

@ -279,7 +279,8 @@ module.exports = class SpellView extends View
]
@onCodeChangeMetaHandler = =>
return if @eventsSuppressed
if not @spellThang or @spell.hasChangedSignificantly @getSource(), @spellThang.aether.raw
@spell.hasChangedSignificantly @getSource(), @spellThang.aether.raw, (hasChanged) =>
if not @spellThang or hasChanged
callback() for callback in onSignificantChange # Do these first
callback() for callback in onAnyChange # Then these
@aceDoc.on 'change', @onCodeChangeMetaHandler
@ -318,11 +319,12 @@ module.exports = class SpellView extends View
# to a new spellThang, we may want to refresh our Aether display.
return unless aether = @spellThang?.aether
source = @getSource()
codeHasChangedSignificantly = force or @spell.hasChangedSignificantly source, aether.raw
@spell.hasChangedSignificantly source, aether.raw, (hasChanged) =>
codeHasChangedSignificantly = force or hasChanged
needsUpdate = codeHasChangedSignificantly or @spellThang isnt @lastUpdatedAetherSpellThang
return if not needsUpdate and aether is @displayedAether
castAether = @spellThang.castAether
codeIsAsCast = castAether and not @spell.hasChangedSignificantly source, castAether.raw
codeIsAsCast = castAether and not hasChanged
aether = castAether if codeIsAsCast
return if not needsUpdate and aether is @displayedAether
@ -417,7 +419,8 @@ module.exports = class SpellView extends View
return @onInfiniteLoop e if e.problem.id is "runtime_InfiniteLoop"
return unless e.problem.userInfo.methodName is @spell.name
return unless spellThang = _.find @spell.thangs, (spellThang, thangID) -> thangID is e.problem.userInfo.thangID
return if @spell.hasChangedSignificantly @getSource() # don't show this error if we've since edited the code
@spell.hasChangedSignificantly @getSource(), null, (hasChanged) =>
return if hasChanged
spellThang.aether.addProblem e.problem
@lastUpdatedAetherSpellThang = null # force a refresh without a re-transpile
@updateAether false, false
@ -595,7 +598,9 @@ module.exports = class SpellView extends View
@aceSession.setMode @editModes[aceConfig.language ? 'javascript']
dismiss: ->
@recompile() if @spell.hasChangedSignificantly @getSource()
@spell.hasChangedSignificantly @getSource(), null, (hasChanged) =>
@recompile() if hasChanged
destroy: ->
$(@ace?.container).find('.ace_gutter').off 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick

View file

@ -215,5 +215,5 @@ module.exports = class TomeView extends View
destroy: ->
spell.destroy() for spellKey, spell of @spells
@worker?._close()
@worker?.terminate()
super()

View file

@ -59,6 +59,7 @@ exports.config =
# Aether before box2d for some strange Object.defineProperty thing
'bower_components/aether/build/aether.js'
'bower_components/d3/d3.min.js'
'vendor/scripts/async.js'
]
stylesheets:
defaultExtension: 'sass'

1043
vendor/scripts/async.js vendored Normal file

File diff suppressed because it is too large Load diff