{"action":"created","issue":{"url":"https://api.github.com/repos/HadoukenIO/core/issues/92","repository_url":"https://api.github.com/repos/HadoukenIO/core","labels_url":"https://api.github.com/repos/HadoukenIO/core/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/HadoukenIO/core/issues/92/comments","events_url":"https://api.github.com/repos/HadoukenIO/core/issues/92/events","html_url":"https://github.com/HadoukenIO/core/pull/92","id":243568068,"number":92,"title":"RUN-3126: Multiple preload scripts","user":{"login":"joneit","id":5996304,"avatar_url":"https://avatars2.githubusercontent.com/u/5996304?v=4","gravatar_id":"","url":"https://api.github.com/users/joneit","html_url":"https://github.com/joneit","followers_url":"https://api.github.com/users/joneit/followers","following_url":"https://api.github.com/users/joneit/following{/other_user}","gists_url":"https://api.github.com/users/joneit/gists{/gist_id}","starred_url":"https://api.github.com/users/joneit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joneit/subscriptions","organizations_url":"https://api.github.com/users/joneit/orgs","repos_url":"https://api.github.com/users/joneit/repos","events_url":"https://api.github.com/users/joneit/events{/privacy}","received_events_url":"https://api.github.com/users/joneit/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-07-18T00:43:05Z","updated_at":"2017-07-25T17:46:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/HadoukenIO/core/pulls/92","html_url":"https://github.com/HadoukenIO/core/pull/92","diff_url":"https://github.com/HadoukenIO/core/pull/92.diff","patch_url":"https://github.com/HadoukenIO/core/pull/92.patch"},"body":"`preload` option can now take an array of preloads in addition to a single (scalar) preload, where \"preload\" is defined as either a URL string primitive, or an object with a `url` property.\r\n\r\nIn addition, these preload objects have the following options:\r\n* `optional` property: When truthy, the preload script does not throw an error on failure to fetch, load, or execute\r\n* `name` property: Useful to running script for reflection\r\n* `index` property: Useful to running script for reflection\r\n\r\n### Algorithm\r\nEach preload is transformed into a \"preload payload,\" a clone of the preload object but with the addition of the following properties. All successfully loaded preloads are returned in an array. Preload payloads extend the source preload objects with the following additional properties:\r\n* `script`: string primitive containing the script itself; omitted on optional script load failure\r\n* `index`: number primitive equal to the element's index in the list\r\n* `result`: One of the following:\r\n   * `undefined`: script has yet to run\r\n   * `true` (or some other truthy object explicitly set by script): script succeeded\r\n   * `Error` object: script failed\r\n\r\n### Script Execution\r\nScripts are `eval`'d in order (synchronously) by the caller.\r\n\r\n### Reflection\r\nAn array object`fin.preloads` is created for the duration of the preload script executions. The entire list of preload payloads is available to each running preload script in this object; a script can dereference its own preload payload object from the list using the `index` property:\r\n```\r\nvar myPreloadPayload = fin.preloads[fin.preloads.index];\r\n```\r\nUsing `name`, `index`, and `result`, scripts can tell which other scripts have already run and their results; and which are yet to run. As mentioned above, the preload payload for those optional scripts that failed to load will have an undefined `script` property.\r\n\r\n### Tests\r\nAdded 6 test runner tests all named beginning with with **\"new Window (multiple preload scripts\"**:\r\n\r\n* new Window (multiple preload scripts, 1 optional bad url)\r\n* new Window (multiple preload scripts, all required, 1 alt spec)\r\n* new Window (multiple preload scripts, all required, 1 bad url)\r\n* new Window (multiple preload scripts, all required, contingent)\r\n* new Window (multiple preload scripts, all required, chained)\r\n* new Window (multiple preload scripts)\r\n\r\nAll are `public` with minimum version `7.53.23.1` — so they will fail until code is merged (they all pass with my local asar).\r\n\r\n### Pending\r\n* Aborting remaining fetches-in-progress when a required fetch fails"},"comment":{"url":"https://api.github.com/repos/HadoukenIO/core/issues/comments/317815045","html_url":"https://github.com/HadoukenIO/core/pull/92#issuecomment-317815045","issue_url":"https://api.github.com/repos/HadoukenIO/core/issues/92","id":317815045,"user":{"login":"joneit","id":5996304,"avatar_url":"https://avatars2.githubusercontent.com/u/5996304?v=4","gravatar_id":"","url":"https://api.github.com/users/joneit","html_url":"https://github.com/joneit","followers_url":"https://api.github.com/users/joneit/followers","following_url":"https://api.github.com/users/joneit/following{/other_user}","gists_url":"https://api.github.com/users/joneit/gists{/gist_id}","starred_url":"https://api.github.com/users/joneit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joneit/subscriptions","organizations_url":"https://api.github.com/users/joneit/orgs","repos_url":"https://api.github.com/users/joneit/repos","events_url":"https://api.github.com/users/joneit/events{/privacy}","received_events_url":"https://api.github.com/users/joneit/received_events","type":"User","site_admin":false},"created_at":"2017-07-25T17:46:06Z","updated_at":"2017-07-25T17:46:06Z","body":"@nicolas @ricardo ok if that's what you want but arrays of string _do_ help to simplify manifest syntax considering 99% of multi-script use cases might look like this:\r\n```\r\n    preload: [\r\n        'http://yada/first-script.js',\r\n        'http://yada/other-script.js'\r\n    ],\r\n```\r\n"}}
{"actor":{"display_login":"joneit"}}