{"action":"opened","issue":{"url":"https://api.github.com/repos/dchambers/composerjs/issues/43","labels_url":"https://api.github.com/repos/dchambers/composerjs/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/dchambers/composerjs/issues/43/comments","events_url":"https://api.github.com/repos/dchambers/composerjs/issues/43/events","html_url":"https://github.com/dchambers/composerjs/issues/43","id":56530328,"number":43,"title":"QUESTION: Should we use use Immutable?","user":{"login":"dchambers","id":283294,"avatar_url":"https://avatars.githubusercontent.com/u/283294?v=3","gravatar_id":"","url":"https://api.github.com/users/dchambers","html_url":"https://github.com/dchambers","followers_url":"https://api.github.com/users/dchambers/followers","following_url":"https://api.github.com/users/dchambers/following{/other_user}","gists_url":"https://api.github.com/users/dchambers/gists{/gist_id}","starred_url":"https://api.github.com/users/dchambers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchambers/subscriptions","organizations_url":"https://api.github.com/users/dchambers/orgs","repos_url":"https://api.github.com/users/dchambers/repos","events_url":"https://api.github.com/users/dchambers/events{/privacy}","received_events_url":"https://api.github.com/users/dchambers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-04T14:08:32Z","updated_at":"2015-02-04T14:08:32Z","closed_at":null,"body":"If we used [Immutable](http://facebook.github.io/immutable-js/) then we could:\r\n\r\n  1. Skip further processing if a handler's output is unchanged.\r\n  1. Update all derived handler inputs after each handler has run (this means less copying, since only a subset of a handler's input properties are likely to have changed).\r\n  1. Only run a handler if it's input properties have changed.\r\n  1. Know that the handler hadn't interfered with the input it had been given.\r\n\r\nThe upshot of this would be that, a summation-handler that is currently implemented like this:\r\n\r\n```js\r\nfunction summationHandler(['x', 'y'], ['sum'], function(input, output, prevInput, prevOutput) {\r\n\toutput.sum = input.x + input.y;\r\n})\r\n```\r\n\r\nwould now be implemented like this:\r\n\r\n```js\r\nfunction summationHandler(['x', 'y'], ['sum'], function(input, output, prevInput) {\r\n\treturn output.set('sum', input.get('x') + input.get('y'));\r\n})\r\n```\r\n\r\nIf we switch to using recursion instead of iteration (as per #34), then we'd need to tie this in with the need to invoke `output.apply()`, so the code would need to be written like this instead:\r\n\r\n```js\r\nfunction summationHandler(['x', 'y'], ['sum'], function(input, output, prevInput) {\r\n\treturn output.set('sum', input.get('x') + input.get('y')).apply();\r\n})\r\n```\r\n"}}