-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async vast loading #45
base: master
Are you sure you want to change the base?
Conversation
README.md
Outdated
Loads and parses IAB VAST tags, resolving wrapped tags along the way. | ||
Loads IAB VAST tag trees using a preorder depth first strategy. The package is statically typed using [Flow](https://flow.org). [Observable streams](http://npmjs.com/package/rxjs) are used to update the consumer in time with new VAST documents. | ||
|
||
This is a major rewrite from the [earlier version](https://github.com/zentrick/iab-vast-loader/tree/v0.8.0) of this package with the main benefit that it asynchronously fetches the complete VAST document tree. The previous version of this package used [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) and waited for the complete VAST tree to be fetched. One failing VAST document within the tree, made it fail completely. Cancellation semantics were also absent, by using Observables, we get them for free. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not have the readme assume that people are familiar with previous versions, or at least not by default. We should move most of this to a section on upgrading.
README.md
Outdated
`10000`. | ||
- `retryCount`: The amount of times it will retry fetching a VAST document in case of failure. The default is `0`. | ||
- `credentials: Credentials`: Controls [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) | ||
behavior. You should pass an array of CredentialsType or functions that return a [CredentialsType value]((https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)), which is either `'omit'`, `'same-origin'` or `'include'`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if typing (or the flow types below) is the best way to convey the API for credentials. Something like "either an array containing any of ['omit', 'same-origin', 'include']
, or a function that maps the request URL to one of those values"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, maybe we want to support a single string as well?
README.md
Outdated
`instanceof` doesn't work for you, you may want to inspect `error.$type` | ||
instead. This issue can occur if you load multiple versions of iab-vast-loader, | ||
each with their own `VASTLoaderError` class. | ||
You can also pass multiple CORS strategies with the array. The implementation will race the different strategies in parallel, and will use the first request that succeeds. If none of the CORS strategies succeed, it will result in a `VAST_LOADING_FAILED` action. Notice that passing an empty array doesn't make sense, because it will make your request to fail always. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "because ..." at the end is kind of weird.
README.md
Outdated
|
||
The maximum number of VAST documents to load within one chain. The default is | ||
10. | ||
The output of loadVast is a stream of VastLoadAction objects: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put identifiers in backticks.
README.md
Outdated
|
||
### `timeout` | ||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again not sure if I'd put flow types in the readme, but I'm not sure how else to do it. I don't want to scare people away just because they don't know about static typing though, because that shouldn't prevent them from using this library.
@@ -0,0 +1,76 @@ | |||
// @flow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we want to publish this as a separate package?
Observable.defer(() => fetch(url, options)) | ||
.mergeMap(res => res.ok ? Observable.fromPromise(res.text()) : Observable.throw(new Error('Http Failed'))) | ||
|
||
export const fx = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's fx stand for? Reactive fetch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fx
stands for effects because these are observables that introduce side effects when you subscribe to them.
|
||
const http = (url: string, options?: RequestOptions) => | ||
Observable.defer(() => fetch(url, options)) | ||
.mergeMap(res => res.ok ? Observable.fromPromise(res.text()) : Observable.throw(new Error('Http Failed'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to subclass Error
for the HTTP-specific things? All fetch
exceptions are just TypeError
s though, so meh.
const fixturesPath = path.resolve(__dirname, '../fixtures') | ||
|
||
const buildVastVars = vastPath => { | ||
const url = 'http://192.168.1.200:8080/' + vastPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this dynamic using e.g. internal-ip?
test/lib/setup.js
Outdated
@@ -4,10 +4,14 @@ import chaiAsPromised from 'chai-as-promised' | |||
import sinon from 'sinon' | |||
import sinonChai from 'sinon-chai' | |||
import dirtyChai from 'dirty-chai' | |||
// import {XMLHttpRequest} from 'xmlhttprequest' | |||
import XMLHttpRequest from 'xhr2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one isn't in package.json.
I'd still like to go over this together when you get back from holiday. 🙂 |
Major rewrite of the loader to allow incrementally loading a VAST tree, with good error handling semantics and support for cancellation.
This PR depends on:
These PRs should be merged and published first (major update) before this one can be merged.