{"action":"created","comment":{"url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/comments/118377159","pull_request_review_id":40163790,"id":118377159,"diff_hunk":"@@ -0,0 +1,235 @@\n+import toposort from 'toposort';\n+import { compose } from 'redux';\n+\n+/**\n+ * Store of middleware functions for composing dependencies\n+ * @type Object\n+ */\n+const middlewares = {};\n+\n+const container = {};\n+\n+/**\n+ * A list of allowed priorities that can be specified as metadata\n+ * @type array\n+ */\n+const PRIORITIES = ['before', 'after'];\n+/**\n+ * When true, DI is blocked\n+ * @type {boolean}\n+ */\n+let initialised = false;\n+\n+/**\n+ * Validates the metadata passed to the injector customisation\n+ * @param object\n+ */\n+const validateMeta = (meta) => {\n+  if (typeof meta.name === undefined) {\n+    throw new Error('Injector.update() called with no \"name\" property specified.');\n+  }\n+  PRIORITIES.forEach(k => {\n+    if (\n+      meta[k] !== undefined &&\n+      (typeof meta[k] !== 'string' && !Array.isArray(meta[k]))\n+    ) {\n+      throw new Error(`Injector.update() key ${k} must be a string or array`);\n+    }\n+  });\n+};\n+\n+/**\n+ * Wrapper function to enforce frozen state of DI container\n+ * @param func\n+ * @returns function\n+ */\n+const protect = (func) => (...params) => {\n+  if (initialised) {\n+    throw new Error('Cannot mutate DI container after it has been initialised');\n+  }\n+\n+  func(...params);\n+};\n+\n+/**\n+ * Creates a display name for a final composed component given all\n+ * the names of the mutations that affected it.\n+ * e.g. my-module(TextField)\n+ * @param original The original registered component\n+ * @param module The list of module names that modified the component\n+ */\n+const createDisplayName = (original, modules) => {\n+  const componentName = (original.displayName || original.name || 'Component');\n+  const names = [componentName, ...modules];\n+\n+  return names.reduce((acc, curr) => `${curr}(${acc})`);\n+};\n+\n+/**\n+ * Ensures that the priority keys are arrays\n+ * @param middleware\n+ * @returns object\n+ */\n+const normaliseMiddleware = (middleware) => {\n+  const normalised = { ...middleware };\n+  PRIORITIES.forEach(k => {\n+    if (!Array.isArray(middleware[k])) {\n+      normalised[k] = middleware[k] ? [middleware[k]] : [];\n+    } else {\n+      normalised[k] = middleware[k];\n+    }\n+  });\n+  return normalised;\n+};\n+\n+/**\n+ * Applies a topological sort to the middlewares and resolves\n+ * priority declarations\n+ * @param middlewareList\n+ * @returns {Array}\n+ */\n+const sortMiddlewares = (middlewareList) => {\n+  const graph = [];\n+  let sortedMiddlewares = [];\n+\n+  middlewareList.forEach(entry => {","path":"client/src/lib/dependency-injection/container.js","position":95,"original_position":95,"commit_id":"6583088d87e68e4022d602ecabfbe5c2695708e8","original_commit_id":"6583088d87e68e4022d602ecabfbe5c2695708e8","user":{"login":"unclecheese","id":654636,"avatar_url":"https://avatars2.githubusercontent.com/u/654636?v=3","gravatar_id":"","url":"https://api.github.com/users/unclecheese","html_url":"https://github.com/unclecheese","followers_url":"https://api.github.com/users/unclecheese/followers","following_url":"https://api.github.com/users/unclecheese/following{/other_user}","gists_url":"https://api.github.com/users/unclecheese/gists{/gist_id}","starred_url":"https://api.github.com/users/unclecheese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unclecheese/subscriptions","organizations_url":"https://api.github.com/users/unclecheese/orgs","repos_url":"https://api.github.com/users/unclecheese/repos","events_url":"https://api.github.com/users/unclecheese/events{/privacy}","received_events_url":"https://api.github.com/users/unclecheese/received_events","type":"User","site_admin":false},"body":"Yeah, that would be \r\n```\r\nInjector.transform('module-b', update => {\r\n  update('Component', HOC);\r\n}, { before: 'module-a' });\r\n```","created_at":"2017-05-24T22:07:19Z","updated_at":"2017-05-24T22:07:19Z","html_url":"https://github.com/silverstripe/silverstripe-admin/pull/70#discussion_r118377159","pull_request_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/comments/118377159"},"html":{"href":"https://github.com/silverstripe/silverstripe-admin/pull/70#discussion_r118377159"},"pull_request":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70"}}},"pull_request":{"url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70","id":120787767,"html_url":"https://github.com/silverstripe/silverstripe-admin/pull/70","diff_url":"https://github.com/silverstripe/silverstripe-admin/pull/70.diff","patch_url":"https://github.com/silverstripe/silverstripe-admin/pull/70.patch","issue_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues/70","number":70,"state":"open","locked":false,"title":"WIP: Pulls/4/react dependency injection","user":{"login":"unclecheese","id":654636,"avatar_url":"https://avatars2.githubusercontent.com/u/654636?v=3","gravatar_id":"","url":"https://api.github.com/users/unclecheese","html_url":"https://github.com/unclecheese","followers_url":"https://api.github.com/users/unclecheese/followers","following_url":"https://api.github.com/users/unclecheese/following{/other_user}","gists_url":"https://api.github.com/users/unclecheese/gists{/gist_id}","starred_url":"https://api.github.com/users/unclecheese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unclecheese/subscriptions","organizations_url":"https://api.github.com/users/unclecheese/orgs","repos_url":"https://api.github.com/users/unclecheese/repos","events_url":"https://api.github.com/users/unclecheese/events{/privacy}","received_events_url":"https://api.github.com/users/unclecheese/received_events","type":"User","site_admin":false},"body":"~~Don't merge. API in active flux and discussion.~~","created_at":"2017-05-16T09:57:17Z","updated_at":"2017-05-24T22:07:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c12a3d791fbc9ae7245723e17425d21b98e5538","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70/commits","review_comments_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70/comments","review_comment_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues/70/comments","statuses_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/statuses/6583088d87e68e4022d602ecabfbe5c2695708e8","head":{"label":"open-sausages:pulls/4/react-dependency-injection","ref":"pulls/4/react-dependency-injection","sha":"6583088d87e68e4022d602ecabfbe5c2695708e8","user":{"login":"open-sausages","id":12824172,"avatar_url":"https://avatars1.githubusercontent.com/u/12824172?v=3","gravatar_id":"","url":"https://api.github.com/users/open-sausages","html_url":"https://github.com/open-sausages","followers_url":"https://api.github.com/users/open-sausages/followers","following_url":"https://api.github.com/users/open-sausages/following{/other_user}","gists_url":"https://api.github.com/users/open-sausages/gists{/gist_id}","starred_url":"https://api.github.com/users/open-sausages/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-sausages/subscriptions","organizations_url":"https://api.github.com/users/open-sausages/orgs","repos_url":"https://api.github.com/users/open-sausages/repos","events_url":"https://api.github.com/users/open-sausages/events{/privacy}","received_events_url":"https://api.github.com/users/open-sausages/received_events","type":"Organization","site_admin":false},"repo":{"id":85015591,"name":"silverstripe-admin","full_name":"open-sausages/silverstripe-admin","owner":{"login":"open-sausages","id":12824172,"avatar_url":"https://avatars1.githubusercontent.com/u/12824172?v=3","gravatar_id":"","url":"https://api.github.com/users/open-sausages","html_url":"https://github.com/open-sausages","followers_url":"https://api.github.com/users/open-sausages/followers","following_url":"https://api.github.com/users/open-sausages/following{/other_user}","gists_url":"https://api.github.com/users/open-sausages/gists{/gist_id}","starred_url":"https://api.github.com/users/open-sausages/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-sausages/subscriptions","organizations_url":"https://api.github.com/users/open-sausages/orgs","repos_url":"https://api.github.com/users/open-sausages/repos","events_url":"https://api.github.com/users/open-sausages/events{/privacy}","received_events_url":"https://api.github.com/users/open-sausages/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-sausages/silverstripe-admin","description":"SilverStripe Admin Component","fork":true,"url":"https://api.github.com/repos/open-sausages/silverstripe-admin","forks_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/forks","keys_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/teams","hooks_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/hooks","issue_events_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/issues/events{/number}","events_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/events","assignees_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/assignees{/user}","branches_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/branches{/branch}","tags_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/tags","blobs_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/languages","stargazers_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/stargazers","contributors_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/contributors","subscribers_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/subscribers","subscription_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/subscription","commits_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/contents/{+path}","compare_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/merges","archive_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/downloads","issues_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/issues{/number}","pulls_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/labels{/name}","releases_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/releases{/id}","deployments_url":"https://api.github.com/repos/open-sausages/silverstripe-admin/deployments","created_at":"2017-03-15T01:38:59Z","updated_at":"2017-03-15T01:39:02Z","pushed_at":"2017-05-24T05:00:28Z","git_url":"git://github.com/open-sausages/silverstripe-admin.git","ssh_url":"git@github.com:open-sausages/silverstripe-admin.git","clone_url":"https://github.com/open-sausages/silverstripe-admin.git","svn_url":"https://github.com/open-sausages/silverstripe-admin","homepage":"","size":7315,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"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":"silverstripe:master","ref":"master","sha":"f207562a21cca9b3d1818becb8d6d62af8be249a","user":{"login":"silverstripe","id":379348,"avatar_url":"https://avatars3.githubusercontent.com/u/379348?v=3","gravatar_id":"","url":"https://api.github.com/users/silverstripe","html_url":"https://github.com/silverstripe","followers_url":"https://api.github.com/users/silverstripe/followers","following_url":"https://api.github.com/users/silverstripe/following{/other_user}","gists_url":"https://api.github.com/users/silverstripe/gists{/gist_id}","starred_url":"https://api.github.com/users/silverstripe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silverstripe/subscriptions","organizations_url":"https://api.github.com/users/silverstripe/orgs","repos_url":"https://api.github.com/users/silverstripe/repos","events_url":"https://api.github.com/users/silverstripe/events{/privacy}","received_events_url":"https://api.github.com/users/silverstripe/received_events","type":"Organization","site_admin":false},"repo":{"id":84500508,"name":"silverstripe-admin","full_name":"silverstripe/silverstripe-admin","owner":{"login":"silverstripe","id":379348,"avatar_url":"https://avatars3.githubusercontent.com/u/379348?v=3","gravatar_id":"","url":"https://api.github.com/users/silverstripe","html_url":"https://github.com/silverstripe","followers_url":"https://api.github.com/users/silverstripe/followers","following_url":"https://api.github.com/users/silverstripe/following{/other_user}","gists_url":"https://api.github.com/users/silverstripe/gists{/gist_id}","starred_url":"https://api.github.com/users/silverstripe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silverstripe/subscriptions","organizations_url":"https://api.github.com/users/silverstripe/orgs","repos_url":"https://api.github.com/users/silverstripe/repos","events_url":"https://api.github.com/users/silverstripe/events{/privacy}","received_events_url":"https://api.github.com/users/silverstripe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/silverstripe/silverstripe-admin","description":"SilverStripe Admin Component","fork":false,"url":"https://api.github.com/repos/silverstripe/silverstripe-admin","forks_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/forks","keys_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/teams","hooks_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/hooks","issue_events_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues/events{/number}","events_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/events","assignees_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/assignees{/user}","branches_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/branches{/branch}","tags_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/tags","blobs_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/languages","stargazers_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/stargazers","contributors_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/contributors","subscribers_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/subscribers","subscription_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/subscription","commits_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/contents/{+path}","compare_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/merges","archive_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/downloads","issues_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues{/number}","pulls_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/labels{/name}","releases_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/releases{/id}","deployments_url":"https://api.github.com/repos/silverstripe/silverstripe-admin/deployments","created_at":"2017-03-10T00:06:07Z","updated_at":"2017-03-14T23:17:40Z","pushed_at":"2017-05-24T05:00:29Z","git_url":"git://github.com/silverstripe/silverstripe-admin.git","ssh_url":"git@github.com:silverstripe/silverstripe-admin.git","clone_url":"https://github.com/silverstripe/silverstripe-admin.git","svn_url":"https://github.com/silverstripe/silverstripe-admin","homepage":"","size":4980,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":21,"forks":16,"open_issues":21,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70"},"html":{"href":"https://github.com/silverstripe/silverstripe-admin/pull/70"},"issue":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues/70"},"comments":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/issues/70/comments"},"review_comments":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70/comments"},"review_comment":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/pulls/70/commits"},"statuses":{"href":"https://api.github.com/repos/silverstripe/silverstripe-admin/statuses/6583088d87e68e4022d602ecabfbe5c2695708e8"}}}}
{"actor":{"display_login":"unclecheese"}}