{"action":"created","comment":{"url":"https://api.github.com/repos/wix/react-module-container/pulls/comments/97700099","pull_request_review_id":18316778,"id":97700099,"diff_hunk":"@@ -8,11 +8,69 @@ class ModuleRegistry {\n   }\n \n   registerComponent(globalID, generator) {\n-    this.registeredComponents[globalID] = generator;\n+      const keys = this.splitGlobalKey(globalID);\n+      const componentLeafKey = keys[keys.length - 1];\n+      const registeredComponentNameSpace = this.buildNameSpace(keys, this.registeredComponents);\n+      registeredComponentNameSpace[componentLeafKey] = generator;\n+  }\n+\n+    /**\n+    * Splits a string key into an array if possible,\n+    * if not returns the key as an array\n+    * @param globalID\n+    * @returns {*}\n+    */\n+  splitGlobalKey(globalID) {\n+        if (typeof globalID === 'string') {\n+            if (globalID.indexOf('.') > -1) {\n+                return globalID.split('.');\n+            } else {\n+                return [globalID];\n+            }\n+        } else {\n+            throw new Error('globalId must be a string');\n+        }\n+    }\n+\n+    /**\n+     * Creates a NS in an object (if missing) and navigates to it\n+     * @param parts - the parts of the path Array\n+     * @param pathObj - the object we are enhancing and fetching from\n+     * @returns {*}\n+     */\n+  buildNameSpace(parts, pathObj){\n+      let currentPart =  pathObj;\n+      for(let i =0; i< (parts.length -1); i++) {\n+        if (!currentPart[parts[i]]){\n+            currentPart[parts[i]] = {};\n+        }\n+        currentPart = currentPart[parts[i]]\n+      }\n+      return currentPart;\n+  }\n+\n+    /**\n+     * Gets a leaf from a namespace path\n+     * @param globalID - string path separated by '.'\n+     * @param pathObj - the object that should contain the leaf\n+     * @returns {*}\n+     */\n+  getFromNameSpace(globalID, pathObj){\n+      let keys = this.splitGlobalKey(globalID);\n+      let currentKey = pathObj;\n+      for(let i = 0; i < keys.length; i++){\n+         if(currentKey[keys[i]]){\n+             currentKey = currentKey[keys[i]];\n+         } else {\n+             currentKey = undefined;\n+             break;\n+         }\n+      }\n+      return currentKey;\n   }\n \n   component(globalID) {\n-    const generator = this.registeredComponents[globalID];\n+    const generator = this.getFromNameSpace(globalID, this.registeredComponents);","path":"src/module-registry.js","position":68,"original_position":68,"commit_id":"a1c0d65c2eb1628ddc759501b4d7625329e5251f","original_commit_id":"a1c0d65c2eb1628ddc759501b4d7625329e5251f","user":{"login":"shahata","id":1764161,"avatar_url":"https://avatars.githubusercontent.com/u/1764161?v=3","gravatar_id":"","url":"https://api.github.com/users/shahata","html_url":"https://github.com/shahata","followers_url":"https://api.github.com/users/shahata/followers","following_url":"https://api.github.com/users/shahata/following{/other_user}","gists_url":"https://api.github.com/users/shahata/gists{/gist_id}","starred_url":"https://api.github.com/users/shahata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahata/subscriptions","organizations_url":"https://api.github.com/users/shahata/orgs","repos_url":"https://api.github.com/users/shahata/repos","events_url":"https://api.github.com/users/shahata/events{/privacy}","received_events_url":"https://api.github.com/users/shahata/received_events","type":"User","site_admin":false},"body":"basically what you are doing here is:\r\n```js\r\nconst generator = _.get(this.registeredComponents, globalID);\r\n```\r\nSo we don't need all this code.","created_at":"2017-01-25T02:43:24Z","updated_at":"2017-01-25T02:51:37Z","html_url":"https://github.com/wix/react-module-container/pull/1#discussion_r97700099","pull_request_url":"https://api.github.com/repos/wix/react-module-container/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/wix/react-module-container/pulls/comments/97700099"},"html":{"href":"https://github.com/wix/react-module-container/pull/1#discussion_r97700099"},"pull_request":{"href":"https://api.github.com/repos/wix/react-module-container/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/wix/react-module-container/pulls/1","id":102707587,"html_url":"https://github.com/wix/react-module-container/pull/1","diff_url":"https://github.com/wix/react-module-container/pull/1.diff","patch_url":"https://github.com/wix/react-module-container/pull/1.patch","issue_url":"https://api.github.com/repos/wix/react-module-container/issues/1","number":1,"state":"open","locked":false,"title":"Support namespace properly","user":{"login":"itaiche","id":2084185,"avatar_url":"https://avatars.githubusercontent.com/u/2084185?v=3","gravatar_id":"","url":"https://api.github.com/users/itaiche","html_url":"https://github.com/itaiche","followers_url":"https://api.github.com/users/itaiche/followers","following_url":"https://api.github.com/users/itaiche/following{/other_user}","gists_url":"https://api.github.com/users/itaiche/gists{/gist_id}","starred_url":"https://api.github.com/users/itaiche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itaiche/subscriptions","organizations_url":"https://api.github.com/users/itaiche/orgs","repos_url":"https://api.github.com/users/itaiche/repos","events_url":"https://api.github.com/users/itaiche/events{/privacy}","received_events_url":"https://api.github.com/users/itaiche/received_events","type":"User","site_admin":false},"body":"Added namespace support to components.","created_at":"2017-01-23T12:14:20Z","updated_at":"2017-01-25T02:51:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a48d2151faa56716b11949067bc8ebbfb250b7d0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wix/react-module-container/pulls/1/commits","review_comments_url":"https://api.github.com/repos/wix/react-module-container/pulls/1/comments","review_comment_url":"https://api.github.com/repos/wix/react-module-container/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wix/react-module-container/issues/1/comments","statuses_url":"https://api.github.com/repos/wix/react-module-container/statuses/a1c0d65c2eb1628ddc759501b4d7625329e5251f","head":{"label":"wix:Support_NameSpaces","ref":"Support_NameSpaces","sha":"a1c0d65c2eb1628ddc759501b4d7625329e5251f","user":{"login":"wix","id":686511,"avatar_url":"https://avatars.githubusercontent.com/u/686511?v=3","gravatar_id":"","url":"https://api.github.com/users/wix","html_url":"https://github.com/wix","followers_url":"https://api.github.com/users/wix/followers","following_url":"https://api.github.com/users/wix/following{/other_user}","gists_url":"https://api.github.com/users/wix/gists{/gist_id}","starred_url":"https://api.github.com/users/wix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wix/subscriptions","organizations_url":"https://api.github.com/users/wix/orgs","repos_url":"https://api.github.com/users/wix/repos","events_url":"https://api.github.com/users/wix/events{/privacy}","received_events_url":"https://api.github.com/users/wix/received_events","type":"Organization","site_admin":false},"repo":{"id":68650426,"name":"react-module-container","full_name":"wix/react-module-container","owner":{"login":"wix","id":686511,"avatar_url":"https://avatars.githubusercontent.com/u/686511?v=3","gravatar_id":"","url":"https://api.github.com/users/wix","html_url":"https://github.com/wix","followers_url":"https://api.github.com/users/wix/followers","following_url":"https://api.github.com/users/wix/following{/other_user}","gists_url":"https://api.github.com/users/wix/gists{/gist_id}","starred_url":"https://api.github.com/users/wix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wix/subscriptions","organizations_url":"https://api.github.com/users/wix/orgs","repos_url":"https://api.github.com/users/wix/repos","events_url":"https://api.github.com/users/wix/events{/privacy}","received_events_url":"https://api.github.com/users/wix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wix/react-module-container","description":null,"fork":false,"url":"https://api.github.com/repos/wix/react-module-container","forks_url":"https://api.github.com/repos/wix/react-module-container/forks","keys_url":"https://api.github.com/repos/wix/react-module-container/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wix/react-module-container/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wix/react-module-container/teams","hooks_url":"https://api.github.com/repos/wix/react-module-container/hooks","issue_events_url":"https://api.github.com/repos/wix/react-module-container/issues/events{/number}","events_url":"https://api.github.com/repos/wix/react-module-container/events","assignees_url":"https://api.github.com/repos/wix/react-module-container/assignees{/user}","branches_url":"https://api.github.com/repos/wix/react-module-container/branches{/branch}","tags_url":"https://api.github.com/repos/wix/react-module-container/tags","blobs_url":"https://api.github.com/repos/wix/react-module-container/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wix/react-module-container/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wix/react-module-container/git/refs{/sha}","trees_url":"https://api.github.com/repos/wix/react-module-container/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wix/react-module-container/statuses/{sha}","languages_url":"https://api.github.com/repos/wix/react-module-container/languages","stargazers_url":"https://api.github.com/repos/wix/react-module-container/stargazers","contributors_url":"https://api.github.com/repos/wix/react-module-container/contributors","subscribers_url":"https://api.github.com/repos/wix/react-module-container/subscribers","subscription_url":"https://api.github.com/repos/wix/react-module-container/subscription","commits_url":"https://api.github.com/repos/wix/react-module-container/commits{/sha}","git_commits_url":"https://api.github.com/repos/wix/react-module-container/git/commits{/sha}","comments_url":"https://api.github.com/repos/wix/react-module-container/comments{/number}","issue_comment_url":"https://api.github.com/repos/wix/react-module-container/issues/comments{/number}","contents_url":"https://api.github.com/repos/wix/react-module-container/contents/{+path}","compare_url":"https://api.github.com/repos/wix/react-module-container/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wix/react-module-container/merges","archive_url":"https://api.github.com/repos/wix/react-module-container/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wix/react-module-container/downloads","issues_url":"https://api.github.com/repos/wix/react-module-container/issues{/number}","pulls_url":"https://api.github.com/repos/wix/react-module-container/pulls{/number}","milestones_url":"https://api.github.com/repos/wix/react-module-container/milestones{/number}","notifications_url":"https://api.github.com/repos/wix/react-module-container/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wix/react-module-container/labels{/name}","releases_url":"https://api.github.com/repos/wix/react-module-container/releases{/id}","deployments_url":"https://api.github.com/repos/wix/react-module-container/deployments","created_at":"2016-09-19T22:02:11Z","updated_at":"2016-11-20T09:03:22Z","pushed_at":"2017-01-23T12:14:20Z","git_url":"git://github.com/wix/react-module-container.git","ssh_url":"git@github.com:wix/react-module-container.git","clone_url":"https://github.com/wix/react-module-container.git","svn_url":"https://github.com/wix/react-module-container","homepage":null,"size":31,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"wix:master","ref":"master","sha":"c0b2c77c42e75a38eabd259ebbe0fcd4f35471b3","user":{"login":"wix","id":686511,"avatar_url":"https://avatars.githubusercontent.com/u/686511?v=3","gravatar_id":"","url":"https://api.github.com/users/wix","html_url":"https://github.com/wix","followers_url":"https://api.github.com/users/wix/followers","following_url":"https://api.github.com/users/wix/following{/other_user}","gists_url":"https://api.github.com/users/wix/gists{/gist_id}","starred_url":"https://api.github.com/users/wix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wix/subscriptions","organizations_url":"https://api.github.com/users/wix/orgs","repos_url":"https://api.github.com/users/wix/repos","events_url":"https://api.github.com/users/wix/events{/privacy}","received_events_url":"https://api.github.com/users/wix/received_events","type":"Organization","site_admin":false},"repo":{"id":68650426,"name":"react-module-container","full_name":"wix/react-module-container","owner":{"login":"wix","id":686511,"avatar_url":"https://avatars.githubusercontent.com/u/686511?v=3","gravatar_id":"","url":"https://api.github.com/users/wix","html_url":"https://github.com/wix","followers_url":"https://api.github.com/users/wix/followers","following_url":"https://api.github.com/users/wix/following{/other_user}","gists_url":"https://api.github.com/users/wix/gists{/gist_id}","starred_url":"https://api.github.com/users/wix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wix/subscriptions","organizations_url":"https://api.github.com/users/wix/orgs","repos_url":"https://api.github.com/users/wix/repos","events_url":"https://api.github.com/users/wix/events{/privacy}","received_events_url":"https://api.github.com/users/wix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wix/react-module-container","description":null,"fork":false,"url":"https://api.github.com/repos/wix/react-module-container","forks_url":"https://api.github.com/repos/wix/react-module-container/forks","keys_url":"https://api.github.com/repos/wix/react-module-container/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wix/react-module-container/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wix/react-module-container/teams","hooks_url":"https://api.github.com/repos/wix/react-module-container/hooks","issue_events_url":"https://api.github.com/repos/wix/react-module-container/issues/events{/number}","events_url":"https://api.github.com/repos/wix/react-module-container/events","assignees_url":"https://api.github.com/repos/wix/react-module-container/assignees{/user}","branches_url":"https://api.github.com/repos/wix/react-module-container/branches{/branch}","tags_url":"https://api.github.com/repos/wix/react-module-container/tags","blobs_url":"https://api.github.com/repos/wix/react-module-container/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wix/react-module-container/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wix/react-module-container/git/refs{/sha}","trees_url":"https://api.github.com/repos/wix/react-module-container/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wix/react-module-container/statuses/{sha}","languages_url":"https://api.github.com/repos/wix/react-module-container/languages","stargazers_url":"https://api.github.com/repos/wix/react-module-container/stargazers","contributors_url":"https://api.github.com/repos/wix/react-module-container/contributors","subscribers_url":"https://api.github.com/repos/wix/react-module-container/subscribers","subscription_url":"https://api.github.com/repos/wix/react-module-container/subscription","commits_url":"https://api.github.com/repos/wix/react-module-container/commits{/sha}","git_commits_url":"https://api.github.com/repos/wix/react-module-container/git/commits{/sha}","comments_url":"https://api.github.com/repos/wix/react-module-container/comments{/number}","issue_comment_url":"https://api.github.com/repos/wix/react-module-container/issues/comments{/number}","contents_url":"https://api.github.com/repos/wix/react-module-container/contents/{+path}","compare_url":"https://api.github.com/repos/wix/react-module-container/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wix/react-module-container/merges","archive_url":"https://api.github.com/repos/wix/react-module-container/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wix/react-module-container/downloads","issues_url":"https://api.github.com/repos/wix/react-module-container/issues{/number}","pulls_url":"https://api.github.com/repos/wix/react-module-container/pulls{/number}","milestones_url":"https://api.github.com/repos/wix/react-module-container/milestones{/number}","notifications_url":"https://api.github.com/repos/wix/react-module-container/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wix/react-module-container/labels{/name}","releases_url":"https://api.github.com/repos/wix/react-module-container/releases{/id}","deployments_url":"https://api.github.com/repos/wix/react-module-container/deployments","created_at":"2016-09-19T22:02:11Z","updated_at":"2016-11-20T09:03:22Z","pushed_at":"2017-01-23T12:14:20Z","git_url":"git://github.com/wix/react-module-container.git","ssh_url":"git@github.com:wix/react-module-container.git","clone_url":"https://github.com/wix/react-module-container.git","svn_url":"https://github.com/wix/react-module-container","homepage":null,"size":31,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wix/react-module-container/pulls/1"},"html":{"href":"https://github.com/wix/react-module-container/pull/1"},"issue":{"href":"https://api.github.com/repos/wix/react-module-container/issues/1"},"comments":{"href":"https://api.github.com/repos/wix/react-module-container/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/wix/react-module-container/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/wix/react-module-container/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wix/react-module-container/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/wix/react-module-container/statuses/a1c0d65c2eb1628ddc759501b4d7625329e5251f"}}}}
{"actor":{"display_login":"shahata"}}