Skip to content

Instantly share code, notes, and snippets.

@postcasio
Created April 15, 2015 16:28
Show Gist options
  • Save postcasio/8efb682ec63ee27f9fd3 to your computer and use it in GitHub Desktop.
Save postcasio/8efb682ec63ee27f9fd3 to your computer and use it in GitHub Desktop.
{
"classes": {
"CommandRegistry": {
"name": "CommandRegistry",
"filename": "src/command-registry.coffee",
"srcUrl": null,
"sections": [],
"classMethods": [],
"instanceMethods": [{
"name": "add",
"sectionName": null,
"srcUrl": null,
"visibility": "Public",
"summary": "Add one or more command listeners associated with a selector.",
"description": "Add one or more command listeners associated with a selector.",
"titledArguments": [{
"title": "Registering One Command",
"description": "",
"arguments": [{
"name": "target",
"description": "A {String} containing a CSS selector or a DOM element. If you pass a selector, the command will be globally associated with all matching elements. The `,` combinator is not currently supported. If you pass a DOM element, the command will be associated with just that element.",
"type": "String",
"isOptional": false
}, {
"name": "commandName",
"description": "A {String} containing the name of a command you want to handle such as `user:insert-date`.",
"type": "String",
"isOptional": false
}, {
"children": [{
"name": "event",
"description": "A standard DOM event instance. Call `stopPropagation` or `stopImmediatePropagation` to terminate bubbling early.",
"type": null,
"isOptional": false
}],
"name": "callback",
"description": "A {Function} to call when the given command is invoked on an element matching the selector. It will be called with `this` referencing the matching DOM node.",
"type": "Function",
"isOptional": false
}]
}, {
"title": "Registering Multiple Commands",
"description": "",
"arguments": [{
"name": "target",
"description": "A {String} containing a CSS selector or a DOM element. If you pass a selector, the commands will be globally associated with all matching elements. The `,` combinator is not currently supported. If you pass a DOM element, the command will be associated with just that element.",
"type": "String",
"isOptional": false
}, {
"name": "commands",
"description": "An {Object} mapping command names like `user:insert-date` to listener {Function}s.",
"type": "Object",
"isOptional": false
}]
}],
"returnValues": [{
"type": "Disposable",
"description": "Returns a {Disposable} on which `.dispose()` can be called to remove the\nadded command handler(s)."
}]
}, {
"name": "findCommands",
"sectionName": null,
"srcUrl": null,
"visibility": "Public",
"summary": "Find all registered commands matching a query.",
"description": "Find all registered commands matching a query.",
"arguments": [{
"children": [{
"name": "target",
"description": "A DOM node that is the hypothetical target of a given command.",
"type": null,
"isOptional": false
}],
"name": "params",
"description": "An {Object} containing one or more of the following keys:",
"type": "Object",
"isOptional": false
}],
"returnValues": [{
"type": "Array",
"description": "Returns an {Array} of {Object}s containing the following keys:\n\n* `name` The name of the command. For example, `user:insert-date`.\n* `displayName` The display name of the command. For example,\n `User: Insert Date`.\n* `jQuery` Present if the command was registered with the legacy\n `$::command` method."
}]
}, {
"name": "dispatch",
"sectionName": null,
"srcUrl": null,
"visibility": "Public",
"summary": "Simulate the dispatch of a command on a DOM node.",
"description": "Simulate the dispatch of a command on a DOM node.\n\nThis can be useful for testing when you want to simulate the invocation of a\ncommand on a detached DOM node. Otherwise, the DOM node in question needs to\nbe attached to the document so the event bubbles up to the root node to be\nprocessed.",
"arguments": [{
"name": "target",
"description": "The DOM node at which to start bubbling the command event.",
"type": null,
"isOptional": false
}, {
"name": "commandName",
"description": "{String} indicating the name of the command to dispatch. ",
"type": "String",
"isOptional": false
}]
}],
"classProperties": [],
"instanceProperties": [],
"visibility": "Public",
"summary": "Associates listener functions with commands in a\ncontext-sensitive way using CSS selectors. You can access a global instance of\nthis class via `atom.commands`, and commands registered there will be\npresented in the command palette.",
"description": "Associates listener functions with commands in a\ncontext-sensitive way using CSS selectors. You can access a global instance of\nthis class via `atom.commands`, and commands registered there will be\npresented in the command palette.\n\nThe global command registry facilitates a style of event handling known as\n*event delegation* that was popularized by jQuery. Atom commands are expressed\nas custom DOM events that can be invoked on the currently focused element via\na key binding or manually via the command palette. Rather than binding\nlisteners for command events directly to DOM nodes, you instead register\ncommand event listeners globally on `atom.commands` and constrain them to\nspecific kinds of elements with CSS selectors.\n\nAs the event bubbles upward through the DOM, all registered event listeners\nwith matching selectors are invoked in order of specificity. In the event of a\nspecificity tie, the most recently registered listener is invoked first. This\nmirrors the \"cascade\" semantics of CSS. Event listeners are invoked in the\ncontext of the current DOM node, meaning `this` always points at\n`event.currentTarget`. As is normally the case with DOM events,\n`stopPropagation` and `stopImmediatePropagation` can be used to terminate the\nbubbling process and prevent invocation of additional listeners.\n\n## Example\n\nHere is a command that inserts the current date in an editor:\n\n```coffee\natom.commands.add 'atom-text-editor',\n 'user:insert-date': (event) ->\n editor = @getModel()\n editor.insertText(new Date().toLocaleString())\n```"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment