{"action":"created","issue":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/397","repository_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/397/labels{/name}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/397/comments","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/397/events","html_url":"https://github.com/mapbox/mapbox-gl-draw/issues/397","id":161831438,"number":397,"title":"Events re-vamp","user":{"login":"davidtheclark","id":628431,"avatar_url":"https://avatars.githubusercontent.com/u/628431?v=3","gravatar_id":"","url":"https://api.github.com/users/davidtheclark","html_url":"https://github.com/davidtheclark","followers_url":"https://api.github.com/users/davidtheclark/followers","following_url":"https://api.github.com/users/davidtheclark/following{/other_user}","gists_url":"https://api.github.com/users/davidtheclark/gists{/gist_id}","starred_url":"https://api.github.com/users/davidtheclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidtheclark/subscriptions","organizations_url":"https://api.github.com/users/davidtheclark/orgs","repos_url":"https://api.github.com/users/davidtheclark/repos","events_url":"https://api.github.com/users/davidtheclark/events{/privacy}","received_events_url":"https://api.github.com/users/davidtheclark/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-06-23T03:12:06Z","updated_at":"2016-06-23T14:10:23Z","closed_at":null,"body":"I think that it may be worth our while to think through and re-vamp all of the events that get emitted by Draw. We could tackle #395, #393, #367, #316, #271, #307, #385, and other undocumented confusions all at once in a little overhaul. \r\n\r\nIssues, questions, and debugging difficulties keep coming up as a result of one of the following:\r\n\r\n- An event that seems like it should exist not existing (e.g. add/create).\r\n- Events are firing in unintuitive or unclear ways.\r\n\r\n*I think we need to more clearly define our intentions, in documentation and tests, about exactly when each event is going to fire*. The event timing should make intuitive sense, and should be useful for Studio.\r\n\r\nI'm going to draft proposed docs for re-vamped events below, and if you think this isn't a silly effort we can alter it according to your feedback, then I'll work on a PR to make it happen.\r\n\r\n**Those of you with more experience trying to use Draw's events in Studio ( @mcwhittemore , @samanpwbb , @ghoshkaj , @tmcw ) please chime in about whether the proposal below would fulfill the needs and make things better** (or if it's not worth trouble).\r\n\r\n---\r\n\r\nI'm thinking maybe all these events should fire *only as a result of user interaction tracked by Draw* — i.e. not when Draw's API is used to programmatically do things like change modes, or add and delete features. (Which would avoid weirdness like this: https://github.com/mapbox/studio/blob/dev-pages/src/datasets_components/editor/index.js#L214)\r\n\r\n### `draw.select`\r\n\r\nFired when one or more features are selected as the result of a user interaction. The following interactions will trigger this event:\r\n\r\n- Click on a feature.\r\n- Create a box-selection that includes a feature.\r\n- Shift-click on a feature to add it to a selection.\r\n\r\nThe event data is an object with the following shape:\r\n\r\n```js\r\n{\r\n  // Array of GeoJSON objects representing the features that were selected\r\n  features: [{..}, {..}, ..]\r\n}\r\n```\r\n\r\n### `draw.deselect`\r\n\r\nFired when one or more features are deselected as the result of a user interaction. The following interactions will trigger this event:\r\n\r\n- Click outside a selected feature (without using shift-click to add to the selection). This includes clicking on no features, or clicking on a different feature to select that one.\r\n\r\nThe event data is an object with the following shape:\r\n\r\n```js\r\n{\r\n  // Array of GeoJSON objects representing the features that were deselected\r\n  features: [{..}, {..}, ..]\r\n}\r\n```\r\n\r\n### `draw.create`\r\n\r\nFired when a feature is created as the result of a user interaction. The following interactions will trigger this event:\r\n\r\n- Finish drawing a feature. Simply clicking will create a Point. A LineString or Polygon is only created when the user has finished drawing it — i.e. double-clicked the last vertex or hit Enter — and the drawn feature is valid.\r\n\r\nThe event data is an object with the following shape:\r\n\r\n```js\r\n{\r\n  // Array of GeoJSON objects representing the features that were created\r\n  features: [{..}, {..}, ..]\r\n}\r\n```\r\n\r\n### `draw.delete`\r\n\r\nFired when one or more features are deleted as the result of a user interaction. The following interactions will trigger this event:\r\n\r\n- Click the Trash button when one or more features are selected in `simple_select` mode.\r\n- Hit the Backspace or Delete keys when one or features are selected in `simple_select` mode.\r\n\r\nThe event data is an object with the following shape:\r\n\r\n```js\r\n{\r\n  // Array of GeoJSON objects representing the features that were deleted\r\n  features: [{..}, {..}, ..]\r\n}\r\n```\r\n\r\n### `draw.update`\r\n\r\nFired when one or more features are updated as the result of a user interaction. The following interactions will trigger this event:\r\n\r\n- Finish moving one or more selected features in `simple_select` mode. The event will only fire when the movement is finished — i.e. when the user releases the mouse button or hits Enter.\r\n- Finish moving the vertex of a selected feature in `direct_select` mode. The event will only fire when the movement is finished — i.e. when the user releases the mouse button or hits Enter.\r\n- Delete the vertex of a selected feature in `direct_select` mode, which can be done by hitting the Backspace or Delete keys or clicking the Trash button.\r\n\r\nThis event will not fire when a feature is created or deleted. To track those interactions, use `draw.create` and `draw.delete`.\r\n\r\nThe event data is an object with the following shape:\r\n\r\n```js\r\n{\r\n  // Array of GeoJSON objects representing the features that were updated\r\n  features: [{..}, {..}, ..]\r\n}\r\n```\r\n\r\n### `draw.modechange`\r\n\r\nFired just after the current mode stops and just before the next mode starts. A render will not happen until after all event handlers have been triggered, so you can force a mode redirect by calling `Draw.changeMode()` inside a `draw.modechange` handler. For information about when modes change, read about the modes.\r\n\r\nThe event data is an object with the following shape:\r\n\r\n```js\r\n{\r\n  // The upcoming mode, i.e. the mode that Draw is changing to\r\n  mode: 'direct_select',\r\n  opts: 123123123, // SEE BELOW!\r\n}\r\n```\r\n\r\n**I do not yet understand the use-case for the info in `opts` so don't know what it should be. See #385.**\r\n"},"comment":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/comments/228061973","html_url":"https://github.com/mapbox/mapbox-gl-draw/issues/397#issuecomment-228061973","issue_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/397","id":228061973,"user":{"login":"davidtheclark","id":628431,"avatar_url":"https://avatars.githubusercontent.com/u/628431?v=3","gravatar_id":"","url":"https://api.github.com/users/davidtheclark","html_url":"https://github.com/davidtheclark","followers_url":"https://api.github.com/users/davidtheclark/followers","following_url":"https://api.github.com/users/davidtheclark/following{/other_user}","gists_url":"https://api.github.com/users/davidtheclark/gists{/gist_id}","starred_url":"https://api.github.com/users/davidtheclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidtheclark/subscriptions","organizations_url":"https://api.github.com/users/davidtheclark/orgs","repos_url":"https://api.github.com/users/davidtheclark/repos","events_url":"https://api.github.com/users/davidtheclark/events{/privacy}","received_events_url":"https://api.github.com/users/davidtheclark/received_events","type":"User","site_admin":false},"created_at":"2016-06-23T14:10:23Z","updated_at":"2016-06-23T14:10:23Z","body":"> Mostly I'm thinking about History events. \r\n\r\nThat makes sense. I don't know any reason not to."}}
{"actor":{"display_login":"davidtheclark"}}