Skip to content

Instantly share code, notes, and snippets.

@alangpierce
Created July 24, 2017 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alangpierce/34b7aa40cda51b0a089a44680bdfed7e to your computer and use it in GitHub Desktop.
Save alangpierce/34b7aa40cda51b0a089a44680bdfed7e to your computer and use it in GitHub Desktop.
Examples of soaked assignments in CoffeeScript
Example from repos/atom/atom/src/main-process/spawner.coffee:
29 | spawnedProcess.on 'close', (code, signal) ->
30 | error ?= new Error("Command failed: #{signal ? code}") if code isnt 0
> 31 | error?.code ?= code
| ^^^^^^^^^^^
32 | error?.stdout ?= stdout
33 | callback?(error, stdout)
Example from repos/atom/atom/src/main-process/spawner.coffee:
30 | error ?= new Error("Command failed: #{signal ? code}") if code isnt 0
31 | error?.code ?= code
> 32 | error?.stdout ?= stdout
| ^^^^^^^^^^^^^
33 | callback?(error, stdout)
34 | # This is necessary if using Powershell 2 on Windows 7 to get the events to raise
Example from repos/atom/atom/src/text-editor.coffee:
479 | @emitter.emit 'did-destroy'
480 | @emitter.clear()
> 481 | @component?.element.component = null
| ^^^^^^^^^^^^^^^^^^^
482 | @component = null
483 | @lineNumberGutter.element = null
Example from repos/atom/atomdoc/src/parser.coffee:
219 | else if argument?
220 | # If not, consume the list as part of the description
> 221 | argument?.text ?= []
| ^^^^^^^^^^^^^^
222 | argument.text.push '\n' + generateList(tokens)
223 |
Example from repos/atom/fuzzy-finder/lib/main.coffee:
20 |
21 | atom.workspace.observePanes (pane) ->
> 22 | pane.observeActiveItem (item) -> item?.lastOpened = Date.now()
| ^^^^^^^^^^^^^^^^
23 |
24 | deactivate: ->
Example from repos/bacon.js/spec/boilerplate/SpecHelper.coffee:
315 | toValue(x) != "<error>"
316 |
> 317 | Bacon.Observable?.prototype.onUnsub = (f) ->
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
318 | self = this
319 | ended = false
Example from repos/codecombat/app/core/Tracker.coffee:
85 | # Errorception
86 | # https://errorception.com/docs/meta
> 87 | _errs?.meta = traits
| ^^^^^^^^^^^
88 |
89 | # Inspectlet
Example from repos/codecombat/app/lib/Angel.coffee:
142 | # Toggle BOX2D_ENABLED during deserialization so that if we have box2d in the namespace, the Collides Components still don't try to create bodies for deserialized Thangs upon attachment.
143 | window.BOX2D_ENABLED = false
> 144 | streamingWorld?.indefiniteLength = @work.indefiniteLength
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145 | @streamingWorld = World.deserialize serialized, @shared.worldClassMap, @shared.lastSerializedWorldFrames, @finishBeholdingWorld(goalStates), startFrame, endFrame, @work.level, streamingWorld
146 | window.BOX2D_ENABLED = true
Example from repos/codecombat/app/lib/Angel.coffee:
161 | for scriptNote in @shared.world.scriptNotes
162 | Backbone.Mediator.publish scriptNote.channel, scriptNote.event
> 163 | @shared.goalManager?.world = world
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
164 | @finishWork()
165 | else
Example from repos/codecombat/app/lib/LevelLoader.coffee:
110 | if window.serverConfig.picoCTF
111 | @supermodel.addRequestResource(url: '/picoctf/problems', success: (picoCTFProblems) =>
> 112 | @level?.picoCTFProblem = _.find picoCTFProblems, pid: @level.get('picoCTFProblem')
| ^^^^^^^^^^^^^^^^^^^^^^
113 | ).load()
114 | if @sessionless
Example from repos/codecombat/app/lib/surface/Lank.coffee:
369 | @sprite.alpha = Math.max 0.5, @sprite.alpha
370 | mark.updateAlpha @thang.alpha for name, mark of @marks
> 371 | @healthBar?.alpha = @thang.alpha
| ^^^^^^^^^^^^^^^^^
372 |
373 | updateRotation: (sprite) ->
Example from repos/codecombat/app/lib/surface/Lank.coffee:
639 | setHighlight: (to, delay) ->
640 | @addMark 'highlight', @options.floatingLayer, 'highlight' if to
> 641 | @marks.highlight?.highlightDelay = delay
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | @marks.highlight?.toggle to and not @dimmed
643 |
Example from repos/codecombat/app/lib/surface/LankBoss.coffee:
312 | lank = null if @options.choosing # Don't select lanks while choosing
313 | if lank isnt @selectedLank
> 314 | @selectedLank?.selected = false
| ^^^^^^^^^^^^^^^^^^^^^^^
315 | lank?.selected = true
316 | @selectedLank = lank
Example from repos/codecombat/app/lib/surface/LankBoss.coffee:
313 | if lank isnt @selectedLank
314 | @selectedLank?.selected = false
> 315 | lank?.selected = true
| ^^^^^^^^^^^^^^
316 | @selectedLank = lank
317 | alive = lank and not (lank.thang.health < 0)
Example from repos/codecombat/app/lib/surface/LankBoss.coffee:
362 | @pendingFlags.splice(i, 1)
363 | @removeLank pendingFlag
> 364 | e.sprite.sprite?.cursor = if @flagCursorLank then 'crosshair' else 'pointer'
| ^^^^^^^^^^^^^^^^^^^^^^^
365 | null
366 |
Example from repos/codecombat/app/lib/surface/Mark.coffee:
89 | else if @thangType then @buildSprite()
90 | else console.error 'Don\'t know how to build mark for', @name
> 91 | @sprite?.mouseEnabled = false
| ^^^^^^^^^^^^^^^^^^^^^
92 | @
93 |
Example from repos/codecombat/app/lib/surface/Mark.coffee:
312 | @sprite.alpha = @alpha * 0.451 / Math.sqrt(worldZ / 2 + 1)
313 | else if @name is 'bounds'
> 314 | @drawsBoundsBorderShape?.alpha = Math.floor @lank.thang.alpha # Stop drawing bounds as soon as alpha is reduced at all
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
315 | else
316 | @sprite.alpha = @alpha
Example from repos/codecombat/app/lib/world/thang.coffee:
62 | componentClass = @world.classMap[componentClass]
63 | else
> 64 | @world?.classMap[componentClass.className] ?= componentClass
| ^^^^^^^^^^^^^^^^
65 | c = new componentClass componentConfig ? {}
66 | c.attach @
Example from repos/codecombat/app/views/core/CreateAccountModal/teacher/TeacherSignupComponent.coffee:
38 | # NOTE: This uses undocumented API calls and might break in future bootstrap releases
39 | modal = $('#create-account-modal').data('bs.modal')
> 40 | modal?.options?.keyboard = false
| ^^^^^^^^^^^^^^^^^^^^^^^^
41 | modal?.escape?()
42 |
Example from repos/codecombat/app/views/editor/level/thangs/ThangsTabView.coffee:
434 | else
435 | @addThangLank = null
> 436 | @surface?.lankBoss.reallyStopMoving = false
| ^^^^^^^^^^^^^^^^^^
437 |
438 | createEssentialComponents: (defaultComponents) ->
Example from repos/codecombat/app/views/editor/level/thangs/ThangsTabView.coffee:
610 | thang.isSelectable = not thang.isLand for thang in @world.thangs # let us select walls and such
611 | @surface?.setWorld @world
> 612 | @surface?.lankBoss.cachedObstacles = false
| ^^^^^^^^^^^^^^^^^^
613 | @selectAddThangType @addThangType, @cloneSourceThang if @addThangType # make another addThang sprite, since the World just refreshed
614 |
Example from repos/codecombat/app/views/play/CampaignView.coffee:
382 | for acID, ac of campaign.get('adjacentCampaigns') ? {}
383 | if _.isString(ac.showIfUnlocked)
> 384 | _.find(@campaigns.models, id: acID)?.locked = false if ac.showIfUnlocked in me.levels()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
385 | else if _.isArray(ac.showIfUnlocked)
386 | _.find(@campaigns.models, id: acID)?.locked = false if _.intersection(ac.showIfUnlocked, me.levels()).length > 0
Example from repos/codecombat/app/views/play/CampaignView.coffee:
384 | _.find(@campaigns.models, id: acID)?.locked = false if ac.showIfUnlocked in me.levels()
385 | else if _.isArray(ac.showIfUnlocked)
> 386 | _.find(@campaigns.models, id: acID)?.locked = false if _.intersection(ac.showIfUnlocked, me.levels()).length > 0
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387 |
388 | context
Example from repos/codecombat/app/views/play/level/tome/Spell.coffee:
199 | updateLanguageAether: (@language) ->
200 | @thang?.aether?.setLanguage @language
> 201 | @thang?.castAether = null
| ^^^^^^^^^^^^^^^^^^
202 | Backbone.Mediator.publish 'tome:spell-changed-language', spell: @, language: @language
203 | if @worker
Example from repos/codecombat/app/views/play/level/tome/SpellView.coffee:
590 | @spellThang = @spell.thang
591 | @createDebugView() unless @debugView
> 592 | @debugView?.thang = @thang
| ^^^^^^^^^^^^^^^^^
593 | @createTranslationView() unless @translationView
594 | @toolbarView?.toggleFlow false
Example from repos/codecombat/app/views/play/level/tome/editor/autocomplete.coffee:
77 |
78 | @editor.setOptions aceOptions
> 79 | @editor.completer?.autoSelect = true
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80 |
81 | copyCompleters: () ->
Example from repos/codecombat/server/commons/Handler.coffee:
155 | projection = {}
156 | projection[field] = 1 for field in req.query.project.split(',')
> 157 | projection?.restricted = 1
| ^^^^^^^^^^^^^^^^^^^^^^
158 | for filter in filters
159 | callback = (err, results) =>
Example from repos/codecombat/server/queues/scoring/processTaskResult.coffee:
9 | return if scoringUtils.simulatorIsTooOld req, res
10 | originalSessionID = req.body?.originalSessionID
> 11 | req.body?.simulator?.user = '' + req.user?._id
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12 | yetiGuru = {}
13 | try
Example from repos/codecombat/server/queues/scoring/recordTwoGames.coffee:
9 | #console.log 'Recording non-chained result of', sessions?[0]?.name, sessions[0]?.metrics?.rank, 'and', sessions?[1]?.name, sessions?[1]?.metrics?.rank
10 | return if scoringUtils.simulatorIsTooOld req, res
> 11 | req.body?.simulator?.user = '' + req.user?._id
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12 |
13 | yetiGuru = clientResponseObject: req.body, isRandomMatch: true
Example from repos/trix/src/trix/elements/trix_editor_element.coffee:
155 | @notify("change")
156 | when "change", "attachment-add", "attachment-edit", "attachment-remove"
> 157 | @inputElement?.value = Trix.serializeToContentType(this, "text/html")
| ^^^^^^^^^^^^^^^^^^^^
158 |
159 | if @editorController
Example from repos/trix/src/trix/inspector/view.coffee:
53 | saveSetting: (key, value) ->
54 | key = @getSettingsKey(key)
> 55 | window.sessionStorage?[key] = value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
56 |
57 | getSettingsKey: (key) ->
Example from repos/trix/src/trix/views/attachment_view.coffee:
100 | attachmentDidChangeUploadProgress: ->
101 | value = @attachment.getUploadProgress()
> 102 | @findProgressElement()?.value = value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103 |
104 | htmlContainsTagName = (html, tagName) ->
Example from repos/trix/src/trix/views/object_view.coffee:
78 |
79 | cacheViewForObject: (view, object) ->
> 80 | @getViewCache()?[object.getCacheKey()] = view
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81 |
82 | garbageCollectCachedViews: ->
Example from repos/vimium/content_scripts/link_hints.coffee:
519 | @activeHintMarker = linksMatched[tabCount]
520 | @activeHintMarker?.classList?.add "vimiumActiveHintMarker"
> 521 | @activeHintMarker?.style?.zIndex = getNextZIndex()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
522 |
523 | linksMatched: linksMatched
Example from repos/yakyak/src/ui/models/conv.coffee:
59 | conv.event.push msg
60 | # update the sort timestamp to list conv first
> 61 | conv?.self_conversation_state?.sort_timestamp = msg.timestamp ? (Date.now() * 1000)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62 | unreadTotal()
63 | updated 'conv'
Example from repos/yakyak/src/ui/models/conv.coffee:
289 | setNotificationLevel: (conv_id, level) ->
290 | return unless c = lookup[conv_id]
> 291 | c.self_conversation_state?.notification_level = level
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
292 | updated 'conv'
293 |
Example from repos/yakyak/src/ui/models/index.coffee:
10 | module.exports = {entity, conv, viewstate, userinput, connection, convsettings, notify}
11 |
> 12 | window?.models = module.exports
| ^^^^^^^^^^^^^^
13 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment