{"action":"created","comment":{"url":"https://api.github.com/repos/nymag/clay-kiln/pulls/comments/47678896","id":47678896,"diff_hunk":"@@ -214,6 +214,54 @@ function createPage() {\n }\n \n /**\n+ * create a child component (from a base ref) and return it's newly generated ref\n+ * @param {string} baseRef e.g. [siteprefix]/components/name\n+ * @returns {Promise}\n+ */\n+function createChildComponent(baseRef) {\n+  return cache.getDataOnly(baseRef).then(function (baseData) {\n+    return cache.createThrough(baseRef + '/instances', baseData).then(function (res) {\n+      return res._ref;\n+    });\n+  });\n+}\n+\n+/**\n+ * find and clone child components, if any\n+ * @param {object} res from creating a component\n+ * @returns {Promise|object}\n+ */\n+function cloneChildComponents(res) {\n+  // after creating the component, see if there are any component lists inside it\n+  var componentList = _.findKey(res, function (val) {\n+      return val._componentList;\n+      // assumes a component will have a maximum of one component list\n+    }),\n+    items = componentList && res[componentList],\n+    promises = items && _.map(items, function (item) {\n+      return createChildComponent(item._ref);\n+    });\n+\n+  if (items && items.length) {\n+    return Promise.all(promises).then(function (newRefs) {\n+      var newRes = _.cloneDeep(res); // create a new object, since we're explicitly modifying the parent component data","path":"services/edit/index.js","position":34,"original_position":34,"commit_id":"54fc09cca6d12dff674db64029e544fcb8b46a35","original_commit_id":"54fc09cca6d12dff674db64029e544fcb8b46a35","user":{"login":"yoshokatana","id":447522,"avatar_url":"https://avatars.githubusercontent.com/u/447522?v=3","gravatar_id":"","url":"https://api.github.com/users/yoshokatana","html_url":"https://github.com/yoshokatana","followers_url":"https://api.github.com/users/yoshokatana/followers","following_url":"https://api.github.com/users/yoshokatana/following{/other_user}","gists_url":"https://api.github.com/users/yoshokatana/gists{/gist_id}","starred_url":"https://api.github.com/users/yoshokatana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yoshokatana/subscriptions","organizations_url":"https://api.github.com/users/yoshokatana/orgs","repos_url":"https://api.github.com/users/yoshokatana/repos","events_url":"https://api.github.com/users/yoshokatana/events{/privacy}","received_events_url":"https://api.github.com/users/yoshokatana/received_events","type":"User","site_admin":false},"body":"it's read-only :-)","created_at":"2015-12-15T18:44:04Z","updated_at":"2015-12-15T18:44:04Z","html_url":"https://github.com/nymag/clay-kiln/pull/309#discussion_r47678896","pull_request_url":"https://api.github.com/repos/nymag/clay-kiln/pulls/309","_links":{"self":{"href":"https://api.github.com/repos/nymag/clay-kiln/pulls/comments/47678896"},"html":{"href":"https://github.com/nymag/clay-kiln/pull/309#discussion_r47678896"},"pull_request":{"href":"https://api.github.com/repos/nymag/clay-kiln/pulls/309"}}},"pull_request":{"url":"https://api.github.com/repos/nymag/clay-kiln/pulls/309","id":53741580,"html_url":"https://github.com/nymag/clay-kiln/pull/309","diff_url":"https://github.com/nymag/clay-kiln/pull/309.diff","patch_url":"https://github.com/nymag/clay-kiln/pull/309.patch","issue_url":"https://api.github.com/repos/nymag/clay-kiln/issues/309","number":309,"state":"closed","locked":false,"title":"clone components inside a component list when cloning the parent component","user":{"login":"yoshokatana","id":447522,"avatar_url":"https://avatars.githubusercontent.com/u/447522?v=3","gravatar_id":"","url":"https://api.github.com/users/yoshokatana","html_url":"https://github.com/yoshokatana","followers_url":"https://api.github.com/users/yoshokatana/followers","following_url":"https://api.github.com/users/yoshokatana/following{/other_user}","gists_url":"https://api.github.com/users/yoshokatana/gists{/gist_id}","starred_url":"https://api.github.com/users/yoshokatana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yoshokatana/subscriptions","organizations_url":"https://api.github.com/users/yoshokatana/orgs","repos_url":"https://api.github.com/users/yoshokatana/repos","events_url":"https://api.github.com/users/yoshokatana/events{/privacy}","received_events_url":"https://api.github.com/users/yoshokatana/received_events","type":"User","site_admin":false},"body":"[trello ticket](https://trello.com/c/Kh8swqKX/32-related-stories-new-style)\n\nWhen you add components via the <kbd>add component</kbd> button, it calls `edit.createComponent` which clones the base data. If that base data contains a component list, this will now clone those components as well.\n\nFor example, say I have a component called \"Related Stories\", that looks like this:\n\n```yaml\ncomponents:\n  related-stories:\n    content:\n      -\n        _ref: /components/related-story\n```\n\nNow that `related-story` will be cloned, rather than having a direct reference to the base data.","created_at":"2015-12-15T18:20:03Z","updated_at":"2015-12-15T18:44:04Z","closed_at":"2015-12-15T18:41:37Z","merged_at":"2015-12-15T18:41:37Z","merge_commit_sha":"c5450066d4e309adb212a51ece54e1e74b851187","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nymag/clay-kiln/pulls/309/commits","review_comments_url":"https://api.github.com/repos/nymag/clay-kiln/pulls/309/comments","review_comment_url":"https://api.github.com/repos/nymag/clay-kiln/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nymag/clay-kiln/issues/309/comments","statuses_url":"https://api.github.com/repos/nymag/clay-kiln/statuses/54fc09cca6d12dff674db64029e544fcb8b46a35","head":{"label":"nymag:deep-clone","ref":"deep-clone","sha":"54fc09cca6d12dff674db64029e544fcb8b46a35","user":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"repo":{"id":35441695,"name":"clay-kiln","full_name":"nymag/clay-kiln","owner":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nymag/clay-kiln","description":"Editing tools for Clay","fork":false,"url":"https://api.github.com/repos/nymag/clay-kiln","forks_url":"https://api.github.com/repos/nymag/clay-kiln/forks","keys_url":"https://api.github.com/repos/nymag/clay-kiln/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nymag/clay-kiln/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nymag/clay-kiln/teams","hooks_url":"https://api.github.com/repos/nymag/clay-kiln/hooks","issue_events_url":"https://api.github.com/repos/nymag/clay-kiln/issues/events{/number}","events_url":"https://api.github.com/repos/nymag/clay-kiln/events","assignees_url":"https://api.github.com/repos/nymag/clay-kiln/assignees{/user}","branches_url":"https://api.github.com/repos/nymag/clay-kiln/branches{/branch}","tags_url":"https://api.github.com/repos/nymag/clay-kiln/tags","blobs_url":"https://api.github.com/repos/nymag/clay-kiln/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nymag/clay-kiln/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nymag/clay-kiln/git/refs{/sha}","trees_url":"https://api.github.com/repos/nymag/clay-kiln/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nymag/clay-kiln/statuses/{sha}","languages_url":"https://api.github.com/repos/nymag/clay-kiln/languages","stargazers_url":"https://api.github.com/repos/nymag/clay-kiln/stargazers","contributors_url":"https://api.github.com/repos/nymag/clay-kiln/contributors","subscribers_url":"https://api.github.com/repos/nymag/clay-kiln/subscribers","subscription_url":"https://api.github.com/repos/nymag/clay-kiln/subscription","commits_url":"https://api.github.com/repos/nymag/clay-kiln/commits{/sha}","git_commits_url":"https://api.github.com/repos/nymag/clay-kiln/git/commits{/sha}","comments_url":"https://api.github.com/repos/nymag/clay-kiln/comments{/number}","issue_comment_url":"https://api.github.com/repos/nymag/clay-kiln/issues/comments{/number}","contents_url":"https://api.github.com/repos/nymag/clay-kiln/contents/{+path}","compare_url":"https://api.github.com/repos/nymag/clay-kiln/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nymag/clay-kiln/merges","archive_url":"https://api.github.com/repos/nymag/clay-kiln/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nymag/clay-kiln/downloads","issues_url":"https://api.github.com/repos/nymag/clay-kiln/issues{/number}","pulls_url":"https://api.github.com/repos/nymag/clay-kiln/pulls{/number}","milestones_url":"https://api.github.com/repos/nymag/clay-kiln/milestones{/number}","notifications_url":"https://api.github.com/repos/nymag/clay-kiln/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nymag/clay-kiln/labels{/name}","releases_url":"https://api.github.com/repos/nymag/clay-kiln/releases{/id}","created_at":"2015-05-11T18:21:37Z","updated_at":"2015-12-02T19:01:41Z","pushed_at":"2015-12-15T18:41:50Z","git_url":"git://github.com/nymag/clay-kiln.git","ssh_url":"git@github.com:nymag/clay-kiln.git","clone_url":"https://github.com/nymag/clay-kiln.git","svn_url":"https://github.com/nymag/clay-kiln","homepage":"","size":929,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":10,"forks":0,"open_issues":10,"watchers":1,"default_branch":"master"}},"base":{"label":"nymag:master","ref":"master","sha":"0088ed6e658a8f71be74d39588ca97fb3787de67","user":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"repo":{"id":35441695,"name":"clay-kiln","full_name":"nymag/clay-kiln","owner":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nymag/clay-kiln","description":"Editing tools for Clay","fork":false,"url":"https://api.github.com/repos/nymag/clay-kiln","forks_url":"https://api.github.com/repos/nymag/clay-kiln/forks","keys_url":"https://api.github.com/repos/nymag/clay-kiln/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nymag/clay-kiln/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nymag/clay-kiln/teams","hooks_url":"https://api.github.com/repos/nymag/clay-kiln/hooks","issue_events_url":"https://api.github.com/repos/nymag/clay-kiln/issues/events{/number}","events_url":"https://api.github.com/repos/nymag/clay-kiln/events","assignees_url":"https://api.github.com/repos/nymag/clay-kiln/assignees{/user}","branches_url":"https://api.github.com/repos/nymag/clay-kiln/branches{/branch}","tags_url":"https://api.github.com/repos/nymag/clay-kiln/tags","blobs_url":"https://api.github.com/repos/nymag/clay-kiln/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nymag/clay-kiln/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nymag/clay-kiln/git/refs{/sha}","trees_url":"https://api.github.com/repos/nymag/clay-kiln/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nymag/clay-kiln/statuses/{sha}","languages_url":"https://api.github.com/repos/nymag/clay-kiln/languages","stargazers_url":"https://api.github.com/repos/nymag/clay-kiln/stargazers","contributors_url":"https://api.github.com/repos/nymag/clay-kiln/contributors","subscribers_url":"https://api.github.com/repos/nymag/clay-kiln/subscribers","subscription_url":"https://api.github.com/repos/nymag/clay-kiln/subscription","commits_url":"https://api.github.com/repos/nymag/clay-kiln/commits{/sha}","git_commits_url":"https://api.github.com/repos/nymag/clay-kiln/git/commits{/sha}","comments_url":"https://api.github.com/repos/nymag/clay-kiln/comments{/number}","issue_comment_url":"https://api.github.com/repos/nymag/clay-kiln/issues/comments{/number}","contents_url":"https://api.github.com/repos/nymag/clay-kiln/contents/{+path}","compare_url":"https://api.github.com/repos/nymag/clay-kiln/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nymag/clay-kiln/merges","archive_url":"https://api.github.com/repos/nymag/clay-kiln/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nymag/clay-kiln/downloads","issues_url":"https://api.github.com/repos/nymag/clay-kiln/issues{/number}","pulls_url":"https://api.github.com/repos/nymag/clay-kiln/pulls{/number}","milestones_url":"https://api.github.com/repos/nymag/clay-kiln/milestones{/number}","notifications_url":"https://api.github.com/repos/nymag/clay-kiln/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nymag/clay-kiln/labels{/name}","releases_url":"https://api.github.com/repos/nymag/clay-kiln/releases{/id}","created_at":"2015-05-11T18:21:37Z","updated_at":"2015-12-02T19:01:41Z","pushed_at":"2015-12-15T18:41:50Z","git_url":"git://github.com/nymag/clay-kiln.git","ssh_url":"git@github.com:nymag/clay-kiln.git","clone_url":"https://github.com/nymag/clay-kiln.git","svn_url":"https://github.com/nymag/clay-kiln","homepage":"","size":929,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":10,"forks":0,"open_issues":10,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nymag/clay-kiln/pulls/309"},"html":{"href":"https://github.com/nymag/clay-kiln/pull/309"},"issue":{"href":"https://api.github.com/repos/nymag/clay-kiln/issues/309"},"comments":{"href":"https://api.github.com/repos/nymag/clay-kiln/issues/309/comments"},"review_comments":{"href":"https://api.github.com/repos/nymag/clay-kiln/pulls/309/comments"},"review_comment":{"href":"https://api.github.com/repos/nymag/clay-kiln/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nymag/clay-kiln/pulls/309/commits"},"statuses":{"href":"https://api.github.com/repos/nymag/clay-kiln/statuses/54fc09cca6d12dff674db64029e544fcb8b46a35"}}}}