{"action":"created","comment":{"url":"https://api.github.com/repos/refractproject/minim/pulls/comments/118963431","pull_request_review_id":40803804,"id":118963431,"diff_hunk":"@@ -0,0 +1,273 @@\n+var _ = require('lodash');\n+var expect = require('../spec-helper').expect;\n+var minim = require('../../lib/minim').namespace();\n+var KeyValuePair = require('../../lib/primitives/key-value-pair');\n+var JSONSerialiser = require('../../lib/serialisers/json');\n+\n+describe('JSON Serialiser', function() {\n+  var serialiser = new JSONSerialiser(minim);\n+\n+  describe('serialisation', function() {\n+    it('serialises a primitive element', function() {\n+      var element = new minim.elements.String('Hello')\n+      var object = serialiser.serialise(element);\n+\n+      expect(object).to.deep.equal({\n+        element: 'string',\n+        meta: {},\n+        attributes: {},\n+        content: 'Hello'\n+      });\n+    });\n+\n+    it('serialises an element containing element', function() {\n+      var string = new minim.elements.String('Hello')\n+      var element = new minim.BaseElement(string);\n+      element.element = 'custom';\n+\n+      var object = serialiser.serialise(element);\n+\n+      expect(object).to.deep.equal({\n+        element: 'custom',\n+        meta: {},\n+        attributes: {},\n+        content: {\n+          element: 'string',\n+          meta: {},\n+          attributes: {},\n+          content: 'Hello'\n+        }\n+      });\n+    });\n+\n+    it('serialises an element containing element array', function() {\n+      var string = new minim.elements.String('Hello')\n+      var element = new minim.elements.Array([string]);\n+\n+      var object = serialiser.serialise(element);\n+\n+      expect(object).to.deep.equal({\n+        element: 'array',\n+        meta: {},\n+        attributes: {},\n+        content: [\n+          {\n+            element: 'string',\n+            meta: {},\n+            attributes: {},\n+            content: 'Hello'\n+          }\n+        ]\n+      });\n+    });\n+\n+    it('serialises an element containing a pair', function() {\n+      var name = new minim.elements.String('name')\n+      var doe = new minim.elements.String('Doe')\n+      var element = new minim.elements.Member(name, doe);\n+\n+      var object = serialiser.serialise(element);\n+\n+      expect(object).to.deep.equal({\n+        element: 'member',\n+        meta: {},\n+        attributes: {},\n+        content: {\n+          key: {\n+            element: 'string',\n+            meta: {},\n+            attributes: {},\n+            content: 'name'\n+          },\n+          value: {\n+            element: 'string',\n+            meta: {},\n+            attributes: {},\n+            content: 'Doe'\n+          },\n+        }\n+      });\n+    });\n+\n+    it('serialises an elements meta', function() {\n+      var doe = new minim.elements.String('Doe')\n+      doe.title = 'Name';\n+\n+      var object = serialiser.serialise(doe);\n+\n+      expect(object).to.deep.equal({\n+        element: 'string',\n+        meta: {\n+          title: 'Name'\n+        },\n+        attributes: {},\n+        content: 'Doe'\n+      });\n+    });\n+\n+    it('serialises an elements attributes', function() {\n+      var element = new minim.elements.String('Hello World')\n+      element.attributes.set('thread', 123);\n+\n+      var object = serialiser.serialise(element);\n+\n+      expect(object).to.deep.equal({\n+        element: 'string',\n+        meta: {},\n+        attributes: {\n+          thread: 123\n+        },\n+        content: 'Hello World'\n+      });\n+    });\n+  });\n+\n+  describe('deserialisation', function() {\n+    it('deserialise from a JSON object', function() {\n+      var element = serialiser.deserialise({\n+        element: 'string',\n+        content: 'Hello'\n+      });\n+\n+      expect(element).to.be.instanceof(minim.elements.String);\n+      expect(element.content).to.equal('Hello');\n+    });\n+\n+    it('deserialise from a JSON object containing an sub-element', function() {\n+      var element = serialiser.deserialise({\n+        element: 'custom',\n+        content: {\n+          element: 'string',\n+          content: 'Hello',\n+        }\n+      });\n+\n+      expect(element).to.be.instanceof(minim.BaseElement);\n+      expect(element.content).to.be.instanceof(minim.elements.String);\n+      expect(element.content.content).to.equal('Hello');\n+    });\n+\n+    it('deserialise from a JSON object containing an array of elements', function() {\n+      var element = serialiser.deserialise({\n+        element: 'array',\n+        content: [\n+          {\n+            element: 'string',\n+            content: 'Hello',\n+          }\n+        ]\n+      });\n+\n+      expect(element).to.be.instanceof(minim.elements.Array);\n+      expect(element.content[0]).to.be.instanceof(minim.elements.String);\n+      expect(element.content[0].content).to.equal('Hello');\n+    });\n+\n+    it('deserialise from a JSON object containing a key-value pair', function() {\n+      var element = serialiser.deserialise({\n+        element: 'member',\n+        content: {\n+          key: {\n+            element: 'string',\n+            content: 'name',\n+          },\n+          value: {\n+            element: 'string',\n+            content: 'Doe'\n+          }\n+        }\n+      });\n+\n+      expect(element).to.be.instanceof(minim.elements.Member);\n+      expect(element.content).to.be.instanceof(KeyValuePair);\n+      expect(element.key).to.be.instanceof(minim.elements.String);\n+      expect(element.key.content).to.equal('name');\n+      expect(element.value).to.be.instanceof(minim.elements.String);\n+      expect(element.value.content).to.equal('Doe');\n+    });\n+\n+    it('deserialise meta', function() {\n+      var element = serialiser.deserialise({\n+        element: 'string',\n+        meta: {\n+          title: 'hello'\n+        }\n+      });\n+\n+      expect(element.title).to.be.instanceof(minim.elements.String);\n+      expect(element.title.content).to.equal('hello');\n+    });\n+\n+    it('deserialise refracted meta', function() {\n+      var element = serialiser.deserialise({\n+        element: 'string',\n+        meta: {\n+          title: {\n+            element: 'string',\n+            content: 'hello'\n+          }\n+        }\n+      });\n+\n+      expect(element.title).to.be.instanceof(minim.elements.String);\n+      expect(element.title.content).to.equal('hello');\n+    });\n+\n+\n+    it('deserialise attributes', function() {\n+      var element = serialiser.deserialise({\n+        element: 'string',\n+        attributes: {\n+          thing: 'hello'\n+        }\n+      });\n+\n+      const attribute = element.attributes.get('thing');\n+      expect(attribute).to.be.instanceof(minim.elements.String);\n+      expect(attribute.content).to.equal('hello');\n+    });\n+\n+    it('deserialise refracted attributes', function() {\n+      var element = serialiser.deserialise({\n+        element: 'string',\n+        attributes: {\n+          thing: {\n+            element: 'string',\n+            content: 'hello'\n+          }\n+        }\n+      });\n+\n+      const attribute = element.attributes.get('thing');\n+      expect(attribute).to.be.instanceof(minim.elements.String);\n+      expect(attribute.content).to.equal('hello');\n+    });\n+","path":"test/serialisers/json.js","position":229,"original_position":245,"commit_id":"41f6ff8ec70da81cd4b33e3c8b64a1470d5b11e2","original_commit_id":"fb2effbd4c3f3a4439a7bec86b997d6329765647","user":{"login":"pksunkara","id":174703,"avatar_url":"https://avatars3.githubusercontent.com/u/174703?v=3","gravatar_id":"","url":"https://api.github.com/users/pksunkara","html_url":"https://github.com/pksunkara","followers_url":"https://api.github.com/users/pksunkara/followers","following_url":"https://api.github.com/users/pksunkara/following{/other_user}","gists_url":"https://api.github.com/users/pksunkara/gists{/gist_id}","starred_url":"https://api.github.com/users/pksunkara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pksunkara/subscriptions","organizations_url":"https://api.github.com/users/pksunkara/orgs","repos_url":"https://api.github.com/users/pksunkara/repos","events_url":"https://api.github.com/users/pksunkara/events{/privacy}","received_events_url":"https://api.github.com/users/pksunkara/received_events","type":"User","site_admin":false},"body":"Object Deserialise?","created_at":"2017-05-29T16:29:52Z","updated_at":"2017-05-29T16:29:52Z","html_url":"https://github.com/refractproject/minim/pull/114#discussion_r118963431","pull_request_url":"https://api.github.com/repos/refractproject/minim/pulls/114","_links":{"self":{"href":"https://api.github.com/repos/refractproject/minim/pulls/comments/118963431"},"html":{"href":"https://github.com/refractproject/minim/pull/114#discussion_r118963431"},"pull_request":{"href":"https://api.github.com/repos/refractproject/minim/pulls/114"}}},"pull_request":{"url":"https://api.github.com/repos/refractproject/minim/pulls/114","id":122792913,"html_url":"https://github.com/refractproject/minim/pull/114","diff_url":"https://github.com/refractproject/minim/pull/114.diff","patch_url":"https://github.com/refractproject/minim/pull/114.patch","issue_url":"https://api.github.com/repos/refractproject/minim/issues/114","number":114,"state":"open","locked":false,"title":"Untangling spaghetti","user":{"login":"kylef","id":44164,"avatar_url":"https://avatars2.githubusercontent.com/u/44164?v=3","gravatar_id":"","url":"https://api.github.com/users/kylef","html_url":"https://github.com/kylef","followers_url":"https://api.github.com/users/kylef/followers","following_url":"https://api.github.com/users/kylef/following{/other_user}","gists_url":"https://api.github.com/users/kylef/gists{/gist_id}","starred_url":"https://api.github.com/users/kylef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylef/subscriptions","organizations_url":"https://api.github.com/users/kylef/orgs","repos_url":"https://api.github.com/users/kylef/repos","events_url":"https://api.github.com/users/kylef/events{/privacy}","received_events_url":"https://api.github.com/users/kylef/received_events","type":"User","site_admin":false},"body":"This pull request hugely refactors Minims architecture to decouple some of the components. Elements are no longer responsible for serialisation and now don't even know what a namespace is. Serialisation is now [composable](https://en.wikipedia.org/wiki/Composability).\r\n\r\n- Elements no longer know about namespaces.\r\n- There is a new `KeyValuePair` type which removes some special-cases of the MemberElement which used an object as its content. We no longer use an arbitrary object with stringy keys.\r\n- bd63f1e1c5fdb33cf341a7da784e382bb3646d47  - `Element.toValue()` is now generic and can handle all valid elements. This means that we do not have to customise `toValue` in subclasses. We can expect `toValue` to \"just work\" for any element type. We do not need upfront knowledge of element semantics to make `toValue` work.\r\n- JSON Serialisation is now decoupled from the Elements themselves and is a separate construct\r\n    - Namespaces provide the existing convince functionality of `toRefract`/`fromRefract` along with a `serialiser` property to easily create a JSON serialiser.\r\n    - It is now easier to extend and customise the serialiser. A subclass of the `JSONSerialiser` can be made overriding functionality. This make it easier for us to provide both the new serialisation format and the existing serialisation format at the same time. We can provide an option of the `JSONSerialiser` to change formats.\r\n      ```javascript\r\n      const serialiser = new JSONSerialiser(namespace, {/* options to optionally refract elements */});\r\n       ```\r\n- Clone no longer relies on knowledge of namespace and JSON serialisation now does direct object copies instead of serialising and deserialising. This should also give us a performance improvement.\r\n\r\nI would recommend reviewing per-commit.\r\n\r\nThis PR solves problems outlined in https://github.com/apiaryio/dredd-transactions/pull/77#discussion_r118586772.","created_at":"2017-05-28T11:52:14Z","updated_at":"2017-05-29T16:29:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"adf0cb26d461aeaa7515dc3ab11e72d728716bc6","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/refractproject/minim/pulls/114/commits","review_comments_url":"https://api.github.com/repos/refractproject/minim/pulls/114/comments","review_comment_url":"https://api.github.com/repos/refractproject/minim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/refractproject/minim/issues/114/comments","statuses_url":"https://api.github.com/repos/refractproject/minim/statuses/41f6ff8ec70da81cd4b33e3c8b64a1470d5b11e2","head":{"label":"refractproject:kylef/refactor","ref":"kylef/refactor","sha":"41f6ff8ec70da81cd4b33e3c8b64a1470d5b11e2","user":{"login":"refractproject","id":10877387,"avatar_url":"https://avatars0.githubusercontent.com/u/10877387?v=3","gravatar_id":"","url":"https://api.github.com/users/refractproject","html_url":"https://github.com/refractproject","followers_url":"https://api.github.com/users/refractproject/followers","following_url":"https://api.github.com/users/refractproject/following{/other_user}","gists_url":"https://api.github.com/users/refractproject/gists{/gist_id}","starred_url":"https://api.github.com/users/refractproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refractproject/subscriptions","organizations_url":"https://api.github.com/users/refractproject/orgs","repos_url":"https://api.github.com/users/refractproject/repos","events_url":"https://api.github.com/users/refractproject/events{/privacy}","received_events_url":"https://api.github.com/users/refractproject/received_events","type":"Organization","site_admin":false},"repo":{"id":29806257,"name":"minim","full_name":"refractproject/minim","owner":{"login":"refractproject","id":10877387,"avatar_url":"https://avatars0.githubusercontent.com/u/10877387?v=3","gravatar_id":"","url":"https://api.github.com/users/refractproject","html_url":"https://github.com/refractproject","followers_url":"https://api.github.com/users/refractproject/followers","following_url":"https://api.github.com/users/refractproject/following{/other_user}","gists_url":"https://api.github.com/users/refractproject/gists{/gist_id}","starred_url":"https://api.github.com/users/refractproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refractproject/subscriptions","organizations_url":"https://api.github.com/users/refractproject/orgs","repos_url":"https://api.github.com/users/refractproject/repos","events_url":"https://api.github.com/users/refractproject/events{/privacy}","received_events_url":"https://api.github.com/users/refractproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/refractproject/minim","description":"A library for interacting with Refract elements","fork":false,"url":"https://api.github.com/repos/refractproject/minim","forks_url":"https://api.github.com/repos/refractproject/minim/forks","keys_url":"https://api.github.com/repos/refractproject/minim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/refractproject/minim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/refractproject/minim/teams","hooks_url":"https://api.github.com/repos/refractproject/minim/hooks","issue_events_url":"https://api.github.com/repos/refractproject/minim/issues/events{/number}","events_url":"https://api.github.com/repos/refractproject/minim/events","assignees_url":"https://api.github.com/repos/refractproject/minim/assignees{/user}","branches_url":"https://api.github.com/repos/refractproject/minim/branches{/branch}","tags_url":"https://api.github.com/repos/refractproject/minim/tags","blobs_url":"https://api.github.com/repos/refractproject/minim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/refractproject/minim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/refractproject/minim/git/refs{/sha}","trees_url":"https://api.github.com/repos/refractproject/minim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/refractproject/minim/statuses/{sha}","languages_url":"https://api.github.com/repos/refractproject/minim/languages","stargazers_url":"https://api.github.com/repos/refractproject/minim/stargazers","contributors_url":"https://api.github.com/repos/refractproject/minim/contributors","subscribers_url":"https://api.github.com/repos/refractproject/minim/subscribers","subscription_url":"https://api.github.com/repos/refractproject/minim/subscription","commits_url":"https://api.github.com/repos/refractproject/minim/commits{/sha}","git_commits_url":"https://api.github.com/repos/refractproject/minim/git/commits{/sha}","comments_url":"https://api.github.com/repos/refractproject/minim/comments{/number}","issue_comment_url":"https://api.github.com/repos/refractproject/minim/issues/comments{/number}","contents_url":"https://api.github.com/repos/refractproject/minim/contents/{+path}","compare_url":"https://api.github.com/repos/refractproject/minim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/refractproject/minim/merges","archive_url":"https://api.github.com/repos/refractproject/minim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/refractproject/minim/downloads","issues_url":"https://api.github.com/repos/refractproject/minim/issues{/number}","pulls_url":"https://api.github.com/repos/refractproject/minim/pulls{/number}","milestones_url":"https://api.github.com/repos/refractproject/minim/milestones{/number}","notifications_url":"https://api.github.com/repos/refractproject/minim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/refractproject/minim/labels{/name}","releases_url":"https://api.github.com/repos/refractproject/minim/releases{/id}","deployments_url":"https://api.github.com/repos/refractproject/minim/deployments","created_at":"2015-01-25T07:12:23Z","updated_at":"2017-04-18T05:34:51Z","pushed_at":"2017-05-28T12:01:14Z","git_url":"git://github.com/refractproject/minim.git","ssh_url":"git@github.com:refractproject/minim.git","clone_url":"https://github.com/refractproject/minim.git","svn_url":"https://github.com/refractproject/minim","homepage":"","size":277,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":22,"forks":4,"open_issues":22,"watchers":13,"default_branch":"master"}},"base":{"label":"refractproject:master","ref":"master","sha":"58a3e44f746f9b863dc954b3b879dd190d74fbcd","user":{"login":"refractproject","id":10877387,"avatar_url":"https://avatars0.githubusercontent.com/u/10877387?v=3","gravatar_id":"","url":"https://api.github.com/users/refractproject","html_url":"https://github.com/refractproject","followers_url":"https://api.github.com/users/refractproject/followers","following_url":"https://api.github.com/users/refractproject/following{/other_user}","gists_url":"https://api.github.com/users/refractproject/gists{/gist_id}","starred_url":"https://api.github.com/users/refractproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refractproject/subscriptions","organizations_url":"https://api.github.com/users/refractproject/orgs","repos_url":"https://api.github.com/users/refractproject/repos","events_url":"https://api.github.com/users/refractproject/events{/privacy}","received_events_url":"https://api.github.com/users/refractproject/received_events","type":"Organization","site_admin":false},"repo":{"id":29806257,"name":"minim","full_name":"refractproject/minim","owner":{"login":"refractproject","id":10877387,"avatar_url":"https://avatars0.githubusercontent.com/u/10877387?v=3","gravatar_id":"","url":"https://api.github.com/users/refractproject","html_url":"https://github.com/refractproject","followers_url":"https://api.github.com/users/refractproject/followers","following_url":"https://api.github.com/users/refractproject/following{/other_user}","gists_url":"https://api.github.com/users/refractproject/gists{/gist_id}","starred_url":"https://api.github.com/users/refractproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refractproject/subscriptions","organizations_url":"https://api.github.com/users/refractproject/orgs","repos_url":"https://api.github.com/users/refractproject/repos","events_url":"https://api.github.com/users/refractproject/events{/privacy}","received_events_url":"https://api.github.com/users/refractproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/refractproject/minim","description":"A library for interacting with Refract elements","fork":false,"url":"https://api.github.com/repos/refractproject/minim","forks_url":"https://api.github.com/repos/refractproject/minim/forks","keys_url":"https://api.github.com/repos/refractproject/minim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/refractproject/minim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/refractproject/minim/teams","hooks_url":"https://api.github.com/repos/refractproject/minim/hooks","issue_events_url":"https://api.github.com/repos/refractproject/minim/issues/events{/number}","events_url":"https://api.github.com/repos/refractproject/minim/events","assignees_url":"https://api.github.com/repos/refractproject/minim/assignees{/user}","branches_url":"https://api.github.com/repos/refractproject/minim/branches{/branch}","tags_url":"https://api.github.com/repos/refractproject/minim/tags","blobs_url":"https://api.github.com/repos/refractproject/minim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/refractproject/minim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/refractproject/minim/git/refs{/sha}","trees_url":"https://api.github.com/repos/refractproject/minim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/refractproject/minim/statuses/{sha}","languages_url":"https://api.github.com/repos/refractproject/minim/languages","stargazers_url":"https://api.github.com/repos/refractproject/minim/stargazers","contributors_url":"https://api.github.com/repos/refractproject/minim/contributors","subscribers_url":"https://api.github.com/repos/refractproject/minim/subscribers","subscription_url":"https://api.github.com/repos/refractproject/minim/subscription","commits_url":"https://api.github.com/repos/refractproject/minim/commits{/sha}","git_commits_url":"https://api.github.com/repos/refractproject/minim/git/commits{/sha}","comments_url":"https://api.github.com/repos/refractproject/minim/comments{/number}","issue_comment_url":"https://api.github.com/repos/refractproject/minim/issues/comments{/number}","contents_url":"https://api.github.com/repos/refractproject/minim/contents/{+path}","compare_url":"https://api.github.com/repos/refractproject/minim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/refractproject/minim/merges","archive_url":"https://api.github.com/repos/refractproject/minim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/refractproject/minim/downloads","issues_url":"https://api.github.com/repos/refractproject/minim/issues{/number}","pulls_url":"https://api.github.com/repos/refractproject/minim/pulls{/number}","milestones_url":"https://api.github.com/repos/refractproject/minim/milestones{/number}","notifications_url":"https://api.github.com/repos/refractproject/minim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/refractproject/minim/labels{/name}","releases_url":"https://api.github.com/repos/refractproject/minim/releases{/id}","deployments_url":"https://api.github.com/repos/refractproject/minim/deployments","created_at":"2015-01-25T07:12:23Z","updated_at":"2017-04-18T05:34:51Z","pushed_at":"2017-05-28T12:01:14Z","git_url":"git://github.com/refractproject/minim.git","ssh_url":"git@github.com:refractproject/minim.git","clone_url":"https://github.com/refractproject/minim.git","svn_url":"https://github.com/refractproject/minim","homepage":"","size":277,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":22,"forks":4,"open_issues":22,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/refractproject/minim/pulls/114"},"html":{"href":"https://github.com/refractproject/minim/pull/114"},"issue":{"href":"https://api.github.com/repos/refractproject/minim/issues/114"},"comments":{"href":"https://api.github.com/repos/refractproject/minim/issues/114/comments"},"review_comments":{"href":"https://api.github.com/repos/refractproject/minim/pulls/114/comments"},"review_comment":{"href":"https://api.github.com/repos/refractproject/minim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/refractproject/minim/pulls/114/commits"},"statuses":{"href":"https://api.github.com/repos/refractproject/minim/statuses/41f6ff8ec70da81cd4b33e3c8b64a1470d5b11e2"}}}}
{"actor":{"display_login":"pksunkara"}}