{"action":"created","issue":{"url":"https://api.github.com/repos/yahoo/react-i13n/issues/22","labels_url":"https://api.github.com/repos/yahoo/react-i13n/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/yahoo/react-i13n/issues/22/comments","events_url":"https://api.github.com/repos/yahoo/react-i13n/issues/22/events","html_url":"https://github.com/yahoo/react-i13n/pull/22","id":86850027,"number":22,"title":"add I13nUtils mixin","user":{"login":"kaesonho","id":3829183,"avatar_url":"https://avatars.githubusercontent.com/u/3829183?v=3","gravatar_id":"","url":"https://api.github.com/users/kaesonho","html_url":"https://github.com/kaesonho","followers_url":"https://api.github.com/users/kaesonho/followers","following_url":"https://api.github.com/users/kaesonho/following{/other_user}","gists_url":"https://api.github.com/users/kaesonho/gists{/gist_id}","starred_url":"https://api.github.com/users/kaesonho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaesonho/subscriptions","organizations_url":"https://api.github.com/users/kaesonho/orgs","repos_url":"https://api.github.com/users/kaesonho/repos","events_url":"https://api.github.com/users/kaesonho/events{/privacy}","received_events_url":"https://api.github.com/users/kaesonho/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-10T05:51:15Z","updated_at":"2015-06-10T05:51:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/yahoo/react-i13n/pulls/22","html_url":"https://github.com/yahoo/react-i13n/pull/22","diff_url":"https://github.com/yahoo/react-i13n/pull/22.diff","patch_url":"https://github.com/yahoo/react-i13n/pull/22.patch"},"body":"@redonkulus @lingyan \r\n\r\nprovide `i13n utils mixins` for users to have a easier way to access i13n node and execute i13n event\r\n(move some shared functions to i13nUtils, to provide a small mixin for i13n functionalities)\r\n\r\n### getI13nNode\r\nwhen we use `createI13nNode` to decorate a node, for example `createI13nNode(Foo)`, it generate a template like\r\n```\r\n<I13nFoo> // everything about i13n and creating i13nNode happens here\r\n     <Foo />\r\n</13nFoo>\r\n```\r\n\r\nin Foo, we might have some case want to access the i13n node, so provide `getI13nNode` to get the nearest i13nNode in context passed from parents. \r\n\r\nIn the end, they are do something like\r\n```\r\nvar I13nUtils = require('react-i13n').I13nUtils;\r\nvar DemoComponent = React.createClass({\r\n    mixins: [I13nUtils],\r\n    displayName: 'DemoComponent',\r\n    render: function() {\r\n        // this.getI13nNode() to access the i13nNode created by createI13nNode\r\n    }\r\n});\r\n```\r\n\r\n### executeI13nEvent\r\npreviously users will have to fire events like\r\n```\r\nvar DemoComponent = React.createClass({\r\n    displayName: 'DemoComponent',\r\n    componentDidMount: function () {\r\n         ReactI13n.getInstance.execute('pageview', {});\r\n    }\r\n});\r\n```\r\n\r\nnow we provide executeI13nEvent for them, we can add some error handling and get the i13nNode into payload for them\r\n```\r\nvar I13nUtils = require('react-i13n').I13nUtils;\r\nvar DemoComponent = React.createClass({\r\n    mixins: [I13nUtils],\r\n    displayName: 'DemoComponent',\r\n    componentDidMount: function () {\r\n        // executeI13nEvent will find the i13nNode and append to the payload for you, which means the final payload will be\r\n        // {i13nNode: [theI13nNode], foo: 'bar'}\r\n        this.executeI13nEvent('someEventName', {foo: 'bar'}, function callback() {\r\n            // callback\r\n        });\r\n    }\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/yahoo/react-i13n/issues/comments/110598792","html_url":"https://github.com/yahoo/react-i13n/pull/22#issuecomment-110598792","issue_url":"https://api.github.com/repos/yahoo/react-i13n/issues/22","id":110598792,"user":{"login":"yahoocla","id":6155154,"avatar_url":"https://avatars.githubusercontent.com/u/6155154?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoocla","html_url":"https://github.com/yahoocla","followers_url":"https://api.github.com/users/yahoocla/followers","following_url":"https://api.github.com/users/yahoocla/following{/other_user}","gists_url":"https://api.github.com/users/yahoocla/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoocla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoocla/subscriptions","organizations_url":"https://api.github.com/users/yahoocla/orgs","repos_url":"https://api.github.com/users/yahoocla/repos","events_url":"https://api.github.com/users/yahoocla/events{/privacy}","received_events_url":"https://api.github.com/users/yahoocla/received_events","type":"User","site_admin":false},"created_at":"2015-06-10T05:51:16Z","updated_at":"2015-06-10T05:51:16Z","body":"CLA is valid!"}}