{"action":"closed","issue":{"url":"https://api.github.com/repos/cerebral/cerebral/issues/468","repository_url":"https://api.github.com/repos/cerebral/cerebral","labels_url":"https://api.github.com/repos/cerebral/cerebral/issues/468/labels{/name}","comments_url":"https://api.github.com/repos/cerebral/cerebral/issues/468/comments","events_url":"https://api.github.com/repos/cerebral/cerebral/issues/468/events","html_url":"https://github.com/cerebral/cerebral/issues/468","id":190538337,"number":468,"title":"Connect currying does not work properly [cerebral@2]","user":{"login":"etienne-dldc","id":14336608,"avatar_url":"https://avatars.githubusercontent.com/u/14336608?v=3","gravatar_id":"","url":"https://api.github.com/users/etienne-dldc","html_url":"https://github.com/etienne-dldc","followers_url":"https://api.github.com/users/etienne-dldc/followers","following_url":"https://api.github.com/users/etienne-dldc/following{/other_user}","gists_url":"https://api.github.com/users/etienne-dldc/gists{/gist_id}","starred_url":"https://api.github.com/users/etienne-dldc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etienne-dldc/subscriptions","organizations_url":"https://api.github.com/users/etienne-dldc/orgs","repos_url":"https://api.github.com/users/etienne-dldc/repos","events_url":"https://api.github.com/users/etienne-dldc/events{/privacy}","received_events_url":"https://api.github.com/users/etienne-dldc/received_events","type":"User","site_admin":false},"labels":[{"id":479686927,"url":"https://api.github.com/repos/cerebral/cerebral/labels/cerebral","name":"cerebral","color":"0052cc","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-11-20T04:12:36Z","updated_at":"2016-11-20T23:31:19Z","closed_at":"2016-11-20T23:31:19Z","body":"## The code I'm interesting in\r\n\r\n`src/viewFactories/connect.js`:\r\n```js\r\nexport default HOC => function connect (paths, passedSignals, injectedProps, passedComponent) {\r\n  let component = passedComponent\r\n  let signals = passedSignals\r\n  let props = injectedProps\r\n\r\n  if (arguments.length === 3) {\r\n    component = props\r\n    props = null\r\n  } else if (arguments.length === 2) {\r\n    component = signals\r\n    signals = null\r\n  }\r\n\r\n  if (!component) {\r\n    return function (decoratedComponent) {\r\n      return HOC(paths, signals, props, decoratedComponent)\r\n    }\r\n  }\r\n\r\n  return HOC(paths, signals, props, component)\r\n}\r\n```\r\n\r\n## Problem\r\n\r\nThe `connect` function contains this bit of code: \r\n```js\r\n  if (!component) {\r\n    return function (decoratedComponent) {\r\n      return HOC(paths, signals, props, decoratedComponent)\r\n    }\r\n  }\r\n```\r\nwhich seems to allow currying and so using connect as a Decorator (or in `compose` for Stateless component).\r\n\r\nBut this code does not work because before it, arguments are re-assigned depending on `arguments.length` :\r\n```js\r\n  if (arguments.length === 3) {\r\n    component = props\r\n    props = null\r\n  } else if (arguments.length === 2) {\r\n    component = signals\r\n    signals = null\r\n  }\r\n```\r\nBecause of that the following code **does not works**\r\n```js\r\nconnect(paths, signals)(Component);\r\n// or\r\n@connect(paths, signals)\r\nclass Component {}\r\n// or\r\ncompose(\r\n  connect(paths, signals)\r\n)(Component);\r\n```\r\nIn this case the `arguments.length === 2` condition is `true` and signals are sets in component... and `HOC` is called with the following argument `HOC(paths,null, null, signals)` which is 👎.\r\n\r\nThis mean the only way to make currying works is the following :\r\n```js\r\n@connect(paths, signals, props, null)(Component);\r\n```\r\nWhich is quite annoying...\r\n\r\n## Possible solution\r\n\r\nI think a better API would be the same as `redux` : alway returning a HOC function instead of passing the component as the last argument.\r\n\r\n## Note\r\n\r\nI'm using `cerebral@next` which resolve to `cerebral@2.0.0-0-alpha.5a3d129e`.\r\n"}}
{"actor":{"display_login":"christianalfoni"}}