Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save minodisk/00d8322a4a328d033ff7 to your computer and use it in GitHub Desktop.

Select an option

Save minodisk/00d8322a4a328d033ff7 to your computer and use it in GitHub Desktop.
WorkspaceView#command() を off() する方法
@minodisk
Copy link
Copy Markdown
Author

$::on拡張てことだけど$::offに相当する実装見当たらない。

@minodisk
Copy link
Copy Markdown
Author

https://github.com/atom/space-pen/blob/v3.1.1/src/jquery-extensions.coffee#L146

$.fn.command = (eventName, selector, options, handler) ->
  ...
  @document(eventName, _.humanizeEventName(eventName, options?['doc']))
  @on(eventName, selector, options?['data'], handler)

https://github.com/atom/space-pen/blob/v3.1.1/src/jquery-extensions.coffee#L116

$.fn.document = (eventName, docString) ->
  eventDescriptions = {}
  eventDescriptions[eventName] = docString
  @data('documentation', {}) unless @data('documentation')
  _.extend(@data('documentation'), eventDescriptions)

@document()ではworkspaceView.data('documentation')にeventName/docStringを登録してるだけで、イベント自体はjQueryのon()で聞いてる。よってoffしたい時は普通にoffすればよいぽい。

atom.workspaceView.command 'hoge:action', handler
atom.workspaceView.off 'hoge:action', handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment