{"action":"created","issue":{"url":"https://api.github.com/repos/yahoo/dispatchr/issues/72","labels_url":"https://api.github.com/repos/yahoo/dispatchr/issues/72/labels{/name}","comments_url":"https://api.github.com/repos/yahoo/dispatchr/issues/72/comments","events_url":"https://api.github.com/repos/yahoo/dispatchr/issues/72/events","html_url":"https://github.com/yahoo/dispatchr/issues/72","id":115964834,"number":72,"title":"Unable to affect state asynchronously from store, apply component `this` to handler function?","user":{"login":"jeromecovington","id":486493,"avatar_url":"https://avatars.githubusercontent.com/u/486493?v=3","gravatar_id":"","url":"https://api.github.com/users/jeromecovington","html_url":"https://github.com/jeromecovington","followers_url":"https://api.github.com/users/jeromecovington/followers","following_url":"https://api.github.com/users/jeromecovington/following{/other_user}","gists_url":"https://api.github.com/users/jeromecovington/gists{/gist_id}","starred_url":"https://api.github.com/users/jeromecovington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeromecovington/subscriptions","organizations_url":"https://api.github.com/users/jeromecovington/orgs","repos_url":"https://api.github.com/users/jeromecovington/repos","events_url":"https://api.github.com/users/jeromecovington/events{/privacy}","received_events_url":"https://api.github.com/users/jeromecovington/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-09T21:01:57Z","updated_at":"2015-11-09T21:40:37Z","closed_at":null,"body":"Within a react native app, I do not see a way to apply the component this context to the handler callback function.\r\n```\r\n// ExampleStore.js - store\r\n'use strict';\r\n\r\nvar createStore = require('dispatchr/addons/createStore');\r\nvar Promise = require('bluebird');\r\n\r\nvar ExampleStore = createStore({\r\n  storeName: 'ExampleStore',\r\n  handlers: {\r\n    GET_STATE: function () {\r\n      var endpoint = '/endpoint';\r\n\r\n      var promise = fetch(endpoint)\r\n        .then(response => response.json());\r\n\r\n      return Promise.resolve(promise)\r\n        .then((data) => {\r\n          // this.state is undefined...\r\n          this.state.hasData = true;\r\n          this.state.data = data;\r\n          this.emitChange();\r\n          // ...but can't access component setState(), either.\r\n          this.setState({\r\n            hasData: true,\r\n            data: data\r\n          });\r\n        })\r\n        .done();\r\n    }\r\n  }\r\n});\r\n\r\nmodule.exports = ExampleStore;\r\n\r\n// Example.js - component\r\n'use strict';\r\n\r\nvar React = require('react-native');\r\nvar ExampleStore = require('../../stores/ExampleStore');\r\nvar dispatcher = require('dispatchr').createDispatcher({\r\n  stores: [ExampleStore]\r\n});\r\nvar contextOptions = {};\r\nvar dispatcherContext = dispatcher.createContext(contextOptions);\r\nvar { View } = React;\r\n\r\nvar Example = React.createClass({\r\n  getInitialState: function () {\r\n    return {\r\n      hasData: false,\r\n      data: {}\r\n    };\r\n  },\r\n\r\n  componentDidMount: function () {\r\n    dispatcherContext.dispatch('GET_STATE', {});\r\n  },\r\n\r\n  render: function () {\r\n    return (\r\n      <View></View>\r\n    );\r\n  }\r\n});\r\n\r\nmodule.exports = Example;\r\n```\r\n\r\nIt seems it may be desirable to have a way to apply the component `this` here - https://github.com/yahoo/dispatchr/blob/master/lib/Action.js#L67"},"comment":{"url":"https://api.github.com/repos/yahoo/dispatchr/issues/comments/155206791","html_url":"https://github.com/yahoo/dispatchr/issues/72#issuecomment-155206791","issue_url":"https://api.github.com/repos/yahoo/dispatchr/issues/72","id":155206791,"user":{"login":"mridgway","id":191142,"avatar_url":"https://avatars.githubusercontent.com/u/191142?v=3","gravatar_id":"","url":"https://api.github.com/users/mridgway","html_url":"https://github.com/mridgway","followers_url":"https://api.github.com/users/mridgway/followers","following_url":"https://api.github.com/users/mridgway/following{/other_user}","gists_url":"https://api.github.com/users/mridgway/gists{/gist_id}","starred_url":"https://api.github.com/users/mridgway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mridgway/subscriptions","organizations_url":"https://api.github.com/users/mridgway/orgs","repos_url":"https://api.github.com/users/mridgway/repos","events_url":"https://api.github.com/users/mridgway/events{/privacy}","received_events_url":"https://api.github.com/users/mridgway/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T21:40:36Z","updated_at":"2015-11-09T21:40:36Z","body":"Stores are `EventEmitters`, so you have the component add a change listener and when you call `this.emitChange()` it tells the listener that the store content has changed. Promises are not needed within stores since handlers are completely synchronous."}}