{"action":"created","issue":{"url":"https://api.github.com/repos/codemix/flow-runtime/issues/64","repository_url":"https://api.github.com/repos/codemix/flow-runtime","labels_url":"https://api.github.com/repos/codemix/flow-runtime/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/codemix/flow-runtime/issues/64/comments","events_url":"https://api.github.com/repos/codemix/flow-runtime/issues/64/events","html_url":"https://github.com/codemix/flow-runtime/issues/64","id":211678026,"number":64,"title":"Add FLOW_RUNTIME=namespace configuration","user":{"login":"gajus","id":973543,"avatar_url":"https://avatars1.githubusercontent.com/u/973543?v=3","gravatar_id":"","url":"https://api.github.com/users/gajus","html_url":"https://github.com/gajus","followers_url":"https://api.github.com/users/gajus/followers","following_url":"https://api.github.com/users/gajus/following{/other_user}","gists_url":"https://api.github.com/users/gajus/gists{/gist_id}","starred_url":"https://api.github.com/users/gajus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gajus/subscriptions","organizations_url":"https://api.github.com/users/gajus/orgs","repos_url":"https://api.github.com/users/gajus/repos","events_url":"https://api.github.com/users/gajus/events{/privacy}","received_events_url":"https://api.github.com/users/gajus/received_events","type":"User","site_admin":false},"labels":[{"id":466508747,"url":"https://api.github.com/repos/codemix/flow-runtime/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-03-03T12:41:26Z","updated_at":"2017-03-04T10:58:56Z","closed_at":null,"body":"This is a:\r\n\r\n - [ ] Bug Report\r\n - [x] Feature Request\r\n - [ ] Question\r\n - [ ] Other\r\n\r\nWhich concerns:\r\n\r\n - [x] flow-runtime\r\n - [x] babel-plugin-flow-runtime\r\n - [ ] flow-runtime-validators\r\n - [ ] flow-runtime-mobx\r\n - [ ] flow-config-parser\r\n - [ ] The documentation website\r\n\r\n---\r\n\r\n### What is the current behaviour?\r\n\r\nThe current implementation of `babel-plugin-flow-runtime` allows configuration that either inlines the assertions or skips them at a compile them. This is good enough for developing a library that uses flow-runtime.\r\n\r\n```js\r\nconst add = (a: number, b: number): number => a + b;\r\n\r\n```\r\n\r\nis transformed to:\r\n\r\n```js\r\nimport t from 'flow-runtime';\r\nconst add = (a, b) => {\r\n  let _aType = t.number();\r\n  let _bType = t.number();\r\n  const _returnType = t.return(t.number());\r\n  t.param('a', _aType).assert(a);\r\n  t.param('b', _bType).assert(b);\r\n  return _returnType.assert(a + b);\r\n};\r\n\r\n```\r\n\r\nHowever, it limits library author's ability to distribute code with flow-runtime assertions. I do not want to use dependencies in production that have inlined flow-runtime assertions (for performance reasons).\r\n\r\n---\r\n\r\n### What is the expected behaviour?\r\n\r\nI'd like `babel-plugin-flow-runtime` to accept a configuration that inlines a conditional runtime assertion, e.g.\r\n\r\n```json\r\n{\r\n  \"plugins\": [[\"flow-runtime\", {\r\n    \"assert\": \"applaudience:showtime-api\"\r\n  }]]\r\n}\r\n```\r\n\r\nwould produce code:\r\n\r\n```js\r\nimport t from 'flow-runtime';\r\nconst add = (a, b) => {\r\n  if (process.env.FLOW_RUNTIME && process.env.FLOW_RUNTIME.startsWith('applaudience:showtime-api')) {\r\n    let _aType = t.number();\r\n    let _bType = t.number();\r\n    const _returnType = t.return(t.number());\r\n    t.param('a', _aType).assert(a);\r\n    t.param('b', _bType).assert(b);\r\n    return _returnType.assert(a + b);\r\n  } else {\r\n    return a + b;\r\n  }\r\n};\r\n\r\n```\r\n\r\n> This is a mock implementation. A real-life implementation would follow the [`debug`](https://www.npmjs.com/package/debug) conventions.\r\n\r\nThis way, I could distribute all my codes with inlined `flow-runtime` assertions that users could enable when debugging issues the same way that [`debug`](https://www.npmjs.com/package/debug) is being used, e.g.\r\n\r\n```bash\r\nFLOW_RUNTIME=applaudience:* node ./index.js\r\n\r\n```\r\n\r\nwould enable runtime type assertions for all dependencies under the \"applaudience\" namespace.\r\n\r\n---"},"comment":{"url":"https://api.github.com/repos/codemix/flow-runtime/issues/comments/284144262","html_url":"https://github.com/codemix/flow-runtime/issues/64#issuecomment-284144262","issue_url":"https://api.github.com/repos/codemix/flow-runtime/issues/64","id":284144262,"user":{"login":"gajus","id":973543,"avatar_url":"https://avatars1.githubusercontent.com/u/973543?v=3","gravatar_id":"","url":"https://api.github.com/users/gajus","html_url":"https://github.com/gajus","followers_url":"https://api.github.com/users/gajus/followers","following_url":"https://api.github.com/users/gajus/following{/other_user}","gists_url":"https://api.github.com/users/gajus/gists{/gist_id}","starred_url":"https://api.github.com/users/gajus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gajus/subscriptions","organizations_url":"https://api.github.com/users/gajus/orgs","repos_url":"https://api.github.com/users/gajus/repos","events_url":"https://api.github.com/users/gajus/events{/privacy}","received_events_url":"https://api.github.com/users/gajus/received_events","type":"User","site_admin":false},"created_at":"2017-03-04T10:58:56Z","updated_at":"2017-03-04T10:58:56Z","body":"> These problems aren't unsurmountable, I would just like to avoid them if possible. I would even prefer generating output like this:\r\n\r\nOh, lol. I finished reading your comment after composing my suggestion. At least we agree on an alternative approach. :-)"}}
{"actor":{"display_login":"gajus"}}