{"action":"created","comment":{"url":"https://api.github.com/repos/rtsao/styletron/pulls/comments/103096099","pull_request_review_id":23874120,"id":103096099,"diff_hunk":"@@ -0,0 +1,124 @@\n+const createElement = require('inferno-create-element');\n+const {injectStylePrefixed} = require('styletron-utils');\n+const {\n+  assign,\n+  isNil,\n+  isObject,\n+  isString,\n+  isFunction\n+} = require('./utils');\n+\n+const STYLETRON_KEY = '__STYLETRON';\n+\n+module.exports = styled;\n+\n+/**\n+ * Helper function to create styled components\n+ * @packagename styletron-inferno\n+ * @param  {string|function} name   Tag name or component function/class\n+ * @param  {function|object} styles Style object or function that returns a style object\n+ * @return {function}               Styled component\n+ *\n+ * @example\n+ * import { styled } from 'styletron-inferno';\n+ *\n+ * const Panel = styled('div', {\n+ *   backgroundColor: 'lightblue',\n+ *   fontSize: '12px'\n+ * });\n+ *\n+ * <Panel>Hello World</Panel>\n+ *\n+ * @example\n+ * import { styled } from 'styletron-inferno';\n+ *\n+ * const Panel = styled('div', (props) => ({\n+ *   backgroundColor: props.alert ? 'orange' : 'lightblue',\n+ *   fontSize: '12px'\n+ * }));\n+ *\n+ * <Panel alert>Danger!</Panel>\n+ *\n+ * @example\n+ * import { styled } from 'styletron-inferno';\n+ *\n+ * const DeluxePanel = styled(Panel, (props) => ({\n+ *   backgroundColor: props.alert ? 'red' : 'lime',\n+ *   boxShadow: '3px 3px 3px darkgray',\n+ *   color: 'white'\n+ * }));\n+ *\n+ * <DeluxePanel>Bonjour Monde</DeluxePanel>\n+ */\n+function styled(name, styles) {\n+\n+  // Styled component\n+  if (name && name.hasOwnProperty(STYLETRON_KEY)) {\n+    const component = name[STYLETRON_KEY];\n+    const stylesArray = component.stylesArray.concat(styles);\n+    return createStyledComponent(component.name, stylesArray);\n+\n+  // Tag name or non-styled component\n+  } else if (isString(name) || isFunction(name)) {\n+    return createStyledComponent(name, [styles]);\n+  }\n+\n+  throw new Error('Must pass a tag name or component');\n+}\n+\n+function createStyledComponent(name, stylesArray) {\n+\n+  function StyledComponent(props, context) {\n+    const newProps = assign({}, props);\n+    const styles = resolveStyles(stylesArray, props, context);\n+    const className = injectStylePrefixed(context.styletron, styles);\n+    newProps.className = mergeClassNames(props.className, className);\n+    if (isFunction(props.innerRef)) {\n+      newProps.ref = props.innerRef;\n+      delete newProps.innerRef;\n+    }\n+    return createElement(name, newProps);\n+  }\n+\n+  StyledComponent[STYLETRON_KEY] = {name, stylesArray};\n+\n+  return StyledComponent;\n+}\n+\n+function resolveStyles(stylesArray, props, context) {\n+  const resolvedStyles = {};\n+  for (let i = 0, l = stylesArray.length, styles; i < l; i++) {\n+    styles = stylesArray[i];\n+    if (!isNil(styles)) {\n+      if (isFunction(styles)) {\n+        assign(resolvedStyles, styles(props, context));\n+      } else if (isObject(styles)) {\n+        assign(resolvedStyles, styles);\n+      }\n+    }\n+  }\n+  return resolvedStyles;\n+}\n+\n+const SPACE_REGEX = /\\s+/;\n+\n+function mergeClassNames(classNameA, classNameB) {","path":"packages/styletron-inferno/src/styled.js","position":105,"original_position":105,"commit_id":"e5f49eed515a19ee76b106074f61f89415b1d102","original_commit_id":"e5f49eed515a19ee76b106074f61f89415b1d102","user":{"login":"rtsao","id":780408,"avatar_url":"https://avatars.githubusercontent.com/u/780408?v=3","gravatar_id":"","url":"https://api.github.com/users/rtsao","html_url":"https://github.com/rtsao","followers_url":"https://api.github.com/users/rtsao/followers","following_url":"https://api.github.com/users/rtsao/following{/other_user}","gists_url":"https://api.github.com/users/rtsao/gists{/gist_id}","starred_url":"https://api.github.com/users/rtsao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtsao/subscriptions","organizations_url":"https://api.github.com/users/rtsao/orgs","repos_url":"https://api.github.com/users/rtsao/repos","events_url":"https://api.github.com/users/rtsao/events{/privacy}","received_events_url":"https://api.github.com/users/rtsao/received_events","type":"User","site_admin":false},"body":"I think the addition of de-duplication of class names is a really nice feature, but it potentially makes this function somewhat expensive. I suspect there's room for further optimization here.\r\n\r\nTwo ideas:\r\n1.   Use a stateful regex iteration within a while loop instead of using `String.prototype.split` which involves an array allocation. I suspect building the set of unique classes should be faster this way.\r\n\r\n2. Use of a modified version of `injectStyle` from `styletron-utils` that returns an object with atomic class keys. Then merging can simply be repeated `Object.assign` and then an iteration of the final object keys to build the final class name string. I hadn't thought of this before, but this would definitely have an impact on https://github.com/rtsao/styletron/pull/91","created_at":"2017-02-26T05:46:16Z","updated_at":"2017-02-26T05:53:53Z","html_url":"https://github.com/rtsao/styletron/pull/90#discussion_r103096099","pull_request_url":"https://api.github.com/repos/rtsao/styletron/pulls/90","_links":{"self":{"href":"https://api.github.com/repos/rtsao/styletron/pulls/comments/103096099"},"html":{"href":"https://github.com/rtsao/styletron/pull/90#discussion_r103096099"},"pull_request":{"href":"https://api.github.com/repos/rtsao/styletron/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/rtsao/styletron/pulls/90","id":106775906,"html_url":"https://github.com/rtsao/styletron/pull/90","diff_url":"https://github.com/rtsao/styletron/pull/90.diff","patch_url":"https://github.com/rtsao/styletron/pull/90.patch","issue_url":"https://api.github.com/repos/rtsao/styletron/issues/90","number":90,"state":"open","locked":false,"title":"Added bindings for Inferno","user":{"login":"wagerfield","id":412747,"avatar_url":"https://avatars.githubusercontent.com/u/412747?v=3","gravatar_id":"","url":"https://api.github.com/users/wagerfield","html_url":"https://github.com/wagerfield","followers_url":"https://api.github.com/users/wagerfield/followers","following_url":"https://api.github.com/users/wagerfield/following{/other_user}","gists_url":"https://api.github.com/users/wagerfield/gists{/gist_id}","starred_url":"https://api.github.com/users/wagerfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wagerfield/subscriptions","organizations_url":"https://api.github.com/users/wagerfield/orgs","repos_url":"https://api.github.com/users/wagerfield/repos","events_url":"https://api.github.com/users/wagerfield/events{/privacy}","received_events_url":"https://api.github.com/users/wagerfield/received_events","type":"User","site_admin":false},"body":"It's finally here...Styletron bindings for [Inferno](https://infernojs.org/) 🎉 \r\n\r\nPar a few minor differences, this package behaves in exactly the same way as `styletron-react`. \r\n\r\nThe notable differences are as follows:\r\n\r\n1. `StyletronProvider` is just called `Provider`—the majority of other bindings out there for Redux, MobX etc. all use the non-prefixed `Provider` name, so I thought we should follow convention. If the user is using a number of providers, they can simply name them accordingly when they `import/require` them.\r\n2. The `styled` function params are called `name` and `styles` as opposed to `base` and `styleArg`. `name` is the param name used in Inferno's `createElement` function and `styles`...well just because I don't think `Arg` is needed :)\r\n3. I omitted the `isValidAttr` parser because Inferno handles this internally. Unless I'm missing something, I don't think it's necessary.\r\n4. I made a few optimisations to the `styled` implementation (such as using for loops over lambdas and using a functional component rather than a class component to return the styled component).\r\n5. I also stored the `name` and `stylesArray` on a single `__STYLETRON` object instead of 2 separate keys (`__STYLETRON_STYLES` and `__STYLETRON_TAG`) because I thought it was a little neater.\r\n6. I created some generic `utils` like `assign` and a few type checkers like `isString`, `isObject` etc. These are obviously very generic, so if you're doing these checks anywhere else, perhaps we could hoist them into `styletron-utils` for other `styletron` packages to use and reduce the footprint?\r\n\r\nIn addition to the above, I have also written a pretty comprehensive `README` to compliment the JavaDocs that I have added in `provider.js` and `styled.js`.\r\n\r\nPerhaps the changes above could be rolled into the React version? Happy to do that if you're in agreement.\r\n\r\nThis PR resolves https://github.com/rtsao/styletron/issues/50","created_at":"2017-02-17T17:22:00Z","updated_at":"2017-02-26T05:53:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9038d6114385b1004e0644365f44aa28f72b334f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/rtsao/styletron/pulls/90/commits","review_comments_url":"https://api.github.com/repos/rtsao/styletron/pulls/90/comments","review_comment_url":"https://api.github.com/repos/rtsao/styletron/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rtsao/styletron/issues/90/comments","statuses_url":"https://api.github.com/repos/rtsao/styletron/statuses/e5f49eed515a19ee76b106074f61f89415b1d102","head":{"label":"wagerfield:master","ref":"master","sha":"e5f49eed515a19ee76b106074f61f89415b1d102","user":{"login":"wagerfield","id":412747,"avatar_url":"https://avatars.githubusercontent.com/u/412747?v=3","gravatar_id":"","url":"https://api.github.com/users/wagerfield","html_url":"https://github.com/wagerfield","followers_url":"https://api.github.com/users/wagerfield/followers","following_url":"https://api.github.com/users/wagerfield/following{/other_user}","gists_url":"https://api.github.com/users/wagerfield/gists{/gist_id}","starred_url":"https://api.github.com/users/wagerfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wagerfield/subscriptions","organizations_url":"https://api.github.com/users/wagerfield/orgs","repos_url":"https://api.github.com/users/wagerfield/repos","events_url":"https://api.github.com/users/wagerfield/events{/privacy}","received_events_url":"https://api.github.com/users/wagerfield/received_events","type":"User","site_admin":false},"repo":{"id":78788371,"name":"styletron","full_name":"wagerfield/styletron","owner":{"login":"wagerfield","id":412747,"avatar_url":"https://avatars.githubusercontent.com/u/412747?v=3","gravatar_id":"","url":"https://api.github.com/users/wagerfield","html_url":"https://github.com/wagerfield","followers_url":"https://api.github.com/users/wagerfield/followers","following_url":"https://api.github.com/users/wagerfield/following{/other_user}","gists_url":"https://api.github.com/users/wagerfield/gists{/gist_id}","starred_url":"https://api.github.com/users/wagerfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wagerfield/subscriptions","organizations_url":"https://api.github.com/users/wagerfield/orgs","repos_url":"https://api.github.com/users/wagerfield/repos","events_url":"https://api.github.com/users/wagerfield/events{/privacy}","received_events_url":"https://api.github.com/users/wagerfield/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wagerfield/styletron","description":":zap: Universal, high-performance JavaScript styles","fork":true,"url":"https://api.github.com/repos/wagerfield/styletron","forks_url":"https://api.github.com/repos/wagerfield/styletron/forks","keys_url":"https://api.github.com/repos/wagerfield/styletron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wagerfield/styletron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wagerfield/styletron/teams","hooks_url":"https://api.github.com/repos/wagerfield/styletron/hooks","issue_events_url":"https://api.github.com/repos/wagerfield/styletron/issues/events{/number}","events_url":"https://api.github.com/repos/wagerfield/styletron/events","assignees_url":"https://api.github.com/repos/wagerfield/styletron/assignees{/user}","branches_url":"https://api.github.com/repos/wagerfield/styletron/branches{/branch}","tags_url":"https://api.github.com/repos/wagerfield/styletron/tags","blobs_url":"https://api.github.com/repos/wagerfield/styletron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wagerfield/styletron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wagerfield/styletron/git/refs{/sha}","trees_url":"https://api.github.com/repos/wagerfield/styletron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wagerfield/styletron/statuses/{sha}","languages_url":"https://api.github.com/repos/wagerfield/styletron/languages","stargazers_url":"https://api.github.com/repos/wagerfield/styletron/stargazers","contributors_url":"https://api.github.com/repos/wagerfield/styletron/contributors","subscribers_url":"https://api.github.com/repos/wagerfield/styletron/subscribers","subscription_url":"https://api.github.com/repos/wagerfield/styletron/subscription","commits_url":"https://api.github.com/repos/wagerfield/styletron/commits{/sha}","git_commits_url":"https://api.github.com/repos/wagerfield/styletron/git/commits{/sha}","comments_url":"https://api.github.com/repos/wagerfield/styletron/comments{/number}","issue_comment_url":"https://api.github.com/repos/wagerfield/styletron/issues/comments{/number}","contents_url":"https://api.github.com/repos/wagerfield/styletron/contents/{+path}","compare_url":"https://api.github.com/repos/wagerfield/styletron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wagerfield/styletron/merges","archive_url":"https://api.github.com/repos/wagerfield/styletron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wagerfield/styletron/downloads","issues_url":"https://api.github.com/repos/wagerfield/styletron/issues{/number}","pulls_url":"https://api.github.com/repos/wagerfield/styletron/pulls{/number}","milestones_url":"https://api.github.com/repos/wagerfield/styletron/milestones{/number}","notifications_url":"https://api.github.com/repos/wagerfield/styletron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wagerfield/styletron/labels{/name}","releases_url":"https://api.github.com/repos/wagerfield/styletron/releases{/id}","deployments_url":"https://api.github.com/repos/wagerfield/styletron/deployments","created_at":"2017-01-12T21:26:18Z","updated_at":"2017-01-12T21:26:21Z","pushed_at":"2017-02-17T17:29:19Z","git_url":"git://github.com/wagerfield/styletron.git","ssh_url":"git@github.com:wagerfield/styletron.git","clone_url":"https://github.com/wagerfield/styletron.git","svn_url":"https://github.com/wagerfield/styletron","homepage":"http://styletron.js.org","size":413,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rtsao:master","ref":"master","sha":"b89b44338b23e0811b4cdb66765976e6995f32d3","user":{"login":"rtsao","id":780408,"avatar_url":"https://avatars.githubusercontent.com/u/780408?v=3","gravatar_id":"","url":"https://api.github.com/users/rtsao","html_url":"https://github.com/rtsao","followers_url":"https://api.github.com/users/rtsao/followers","following_url":"https://api.github.com/users/rtsao/following{/other_user}","gists_url":"https://api.github.com/users/rtsao/gists{/gist_id}","starred_url":"https://api.github.com/users/rtsao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtsao/subscriptions","organizations_url":"https://api.github.com/users/rtsao/orgs","repos_url":"https://api.github.com/users/rtsao/repos","events_url":"https://api.github.com/users/rtsao/events{/privacy}","received_events_url":"https://api.github.com/users/rtsao/received_events","type":"User","site_admin":false},"repo":{"id":55190888,"name":"styletron","full_name":"rtsao/styletron","owner":{"login":"rtsao","id":780408,"avatar_url":"https://avatars.githubusercontent.com/u/780408?v=3","gravatar_id":"","url":"https://api.github.com/users/rtsao","html_url":"https://github.com/rtsao","followers_url":"https://api.github.com/users/rtsao/followers","following_url":"https://api.github.com/users/rtsao/following{/other_user}","gists_url":"https://api.github.com/users/rtsao/gists{/gist_id}","starred_url":"https://api.github.com/users/rtsao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtsao/subscriptions","organizations_url":"https://api.github.com/users/rtsao/orgs","repos_url":"https://api.github.com/users/rtsao/repos","events_url":"https://api.github.com/users/rtsao/events{/privacy}","received_events_url":"https://api.github.com/users/rtsao/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rtsao/styletron","description":":zap: Universal, high-performance JavaScript styles","fork":false,"url":"https://api.github.com/repos/rtsao/styletron","forks_url":"https://api.github.com/repos/rtsao/styletron/forks","keys_url":"https://api.github.com/repos/rtsao/styletron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rtsao/styletron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rtsao/styletron/teams","hooks_url":"https://api.github.com/repos/rtsao/styletron/hooks","issue_events_url":"https://api.github.com/repos/rtsao/styletron/issues/events{/number}","events_url":"https://api.github.com/repos/rtsao/styletron/events","assignees_url":"https://api.github.com/repos/rtsao/styletron/assignees{/user}","branches_url":"https://api.github.com/repos/rtsao/styletron/branches{/branch}","tags_url":"https://api.github.com/repos/rtsao/styletron/tags","blobs_url":"https://api.github.com/repos/rtsao/styletron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rtsao/styletron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rtsao/styletron/git/refs{/sha}","trees_url":"https://api.github.com/repos/rtsao/styletron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rtsao/styletron/statuses/{sha}","languages_url":"https://api.github.com/repos/rtsao/styletron/languages","stargazers_url":"https://api.github.com/repos/rtsao/styletron/stargazers","contributors_url":"https://api.github.com/repos/rtsao/styletron/contributors","subscribers_url":"https://api.github.com/repos/rtsao/styletron/subscribers","subscription_url":"https://api.github.com/repos/rtsao/styletron/subscription","commits_url":"https://api.github.com/repos/rtsao/styletron/commits{/sha}","git_commits_url":"https://api.github.com/repos/rtsao/styletron/git/commits{/sha}","comments_url":"https://api.github.com/repos/rtsao/styletron/comments{/number}","issue_comment_url":"https://api.github.com/repos/rtsao/styletron/issues/comments{/number}","contents_url":"https://api.github.com/repos/rtsao/styletron/contents/{+path}","compare_url":"https://api.github.com/repos/rtsao/styletron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rtsao/styletron/merges","archive_url":"https://api.github.com/repos/rtsao/styletron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rtsao/styletron/downloads","issues_url":"https://api.github.com/repos/rtsao/styletron/issues{/number}","pulls_url":"https://api.github.com/repos/rtsao/styletron/pulls{/number}","milestones_url":"https://api.github.com/repos/rtsao/styletron/milestones{/number}","notifications_url":"https://api.github.com/repos/rtsao/styletron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rtsao/styletron/labels{/name}","releases_url":"https://api.github.com/repos/rtsao/styletron/releases{/id}","deployments_url":"https://api.github.com/repos/rtsao/styletron/deployments","created_at":"2016-04-01T00:00:06Z","updated_at":"2017-02-25T16:41:35Z","pushed_at":"2017-02-24T23:25:22Z","git_url":"git://github.com/rtsao/styletron.git","ssh_url":"git@github.com:rtsao/styletron.git","clone_url":"https://github.com/rtsao/styletron.git","svn_url":"https://github.com/rtsao/styletron","homepage":"http://styletron.js.org","size":407,"stargazers_count":1447,"watchers_count":1447,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":32,"forks":28,"open_issues":32,"watchers":1447,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rtsao/styletron/pulls/90"},"html":{"href":"https://github.com/rtsao/styletron/pull/90"},"issue":{"href":"https://api.github.com/repos/rtsao/styletron/issues/90"},"comments":{"href":"https://api.github.com/repos/rtsao/styletron/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/rtsao/styletron/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/rtsao/styletron/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rtsao/styletron/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/rtsao/styletron/statuses/e5f49eed515a19ee76b106074f61f89415b1d102"}}}}
{"actor":{"display_login":"rtsao"}}