{"action":"created","issue":{"url":"https://api.github.com/repos/jrburke/requirejs/issues/1436","labels_url":"https://api.github.com/repos/jrburke/requirejs/issues/1436/labels{/name}","comments_url":"https://api.github.com/repos/jrburke/requirejs/issues/1436/comments","events_url":"https://api.github.com/repos/jrburke/requirejs/issues/1436/events","html_url":"https://github.com/jrburke/requirejs/issues/1436","id":111862211,"number":1436,"title":"FR: let `require([...deps])` returns a Promise","user":{"login":"herby","id":222129,"avatar_url":"https://avatars.githubusercontent.com/u/222129?v=3","gravatar_id":"","url":"https://api.github.com/users/herby","html_url":"https://github.com/herby","followers_url":"https://api.github.com/users/herby/followers","following_url":"https://api.github.com/users/herby/following{/other_user}","gists_url":"https://api.github.com/users/herby/gists{/gist_id}","starred_url":"https://api.github.com/users/herby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/herby/subscriptions","organizations_url":"https://api.github.com/users/herby/orgs","repos_url":"https://api.github.com/users/herby/repos","events_url":"https://api.github.com/users/herby/events{/privacy}","received_events_url":"https://api.github.com/users/herby/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-10-16T16:10:37Z","updated_at":"2015-11-16T17:30:07Z","closed_at":"2015-11-16T07:05:51Z","body":"If callbacks are not provided (or maybe even when they are), the `require([...deps])` call itself should return a promise that is resolved or rejected by array of args that would go to callbacks themselves.\r\n\r\n<del>Additionally, global `Promise` should be reused - so promise is only returned when its constructor is present (otherwise, it should probably return `null`).</del>\r\n\r\nEDIT2: Since there are many promise libs, plus native ES2015 `Promise`, there should be an options for require.config, like `require.config({usePromise: Promise})` in case of native `Promise`. If configured, `require([...])` should use the supplied class to create a promise, if not supplied, it should either return `null` or work as before.\r\n\r\nWrapping the call itself to Promise is not as hard, in fact something like:\r\n\r\n```js\r\nrequire = function (deps) {\r\n  return typeof Promise !== \"function\" ?\r\n    _require.apply(this, arguments) :   \r\n    new Promise(function (resolve, require) {\r\n      _require(deps,\r\n        function () { resolve([].slice.call(arguments)); },\r\n        function () { reject([].slice.call(arguments)); });\r\n    });\r\n};\r\n```\r\n\r\nwhen creating the `require` should be enough given `_require` is current, promiseless version of require.\r\n\r\nEDIT: This FR is about all `require`s, not just the root one - let all `requires`, nested as well as root one, return a Promise when called the async way."},"comment":{"url":"https://api.github.com/repos/jrburke/requirejs/issues/comments/157110186","html_url":"https://github.com/jrburke/requirejs/issues/1436#issuecomment-157110186","issue_url":"https://api.github.com/repos/jrburke/requirejs/issues/1436","id":157110186,"user":{"login":"jrburke","id":73359,"avatar_url":"https://avatars.githubusercontent.com/u/73359?v=3","gravatar_id":"","url":"https://api.github.com/users/jrburke","html_url":"https://github.com/jrburke","followers_url":"https://api.github.com/users/jrburke/followers","following_url":"https://api.github.com/users/jrburke/following{/other_user}","gists_url":"https://api.github.com/users/jrburke/gists{/gist_id}","starred_url":"https://api.github.com/users/jrburke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrburke/subscriptions","organizations_url":"https://api.github.com/users/jrburke/orgs","repos_url":"https://api.github.com/users/jrburke/repos","events_url":"https://api.github.com/users/jrburke/events{/privacy}","received_events_url":"https://api.github.com/users/jrburke/received_events","type":"User","site_admin":false},"created_at":"2015-11-16T17:30:07Z","updated_at":"2015-11-16T17:30:07Z","body":"I would much rather do that change in a loader that already has promise awareness. At the very least it would need to be in a non-2.1.x requirejs release given the API change. I consider alameda the 3.0 exploratory effort, for the rewritten internals, so would prefer to do the change over there."}}