Skip to content
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

Add static typing #39

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Add static typing #39

wants to merge 25 commits into from

Conversation

laurentdesmet
Copy link

Add static typing using flow + newly generated docs.

@laurentdesmet laurentdesmet requested a review from timdp May 2, 2017 08:45
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 951c71c on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 9130d70 on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5db8cc0 on add-flow-types into c042d6a on master.

@laurentdesmet
Copy link
Author

I noticed some of the types can be further narrowed down to a smaller subset, increasing the quality of the types so I would wait to merge this one right now. I'll further improve the types this week.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.694% when pulling 76f3d43 on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 97.605% when pulling ae2e56f on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0bd4e40 on add-flow-types into c042d6a on master.

@laurentdesmet
Copy link
Author

@timdp This PR is ready to be reviewed again. I added static typing to all the src files, and also the tests. Added extra tests to cover the newly added methods and added a few typing fixes for our tests. For every property, I checked the VAST 3 and 4 xsd and usage in the iab-vast-parser to find out if it should be a maybe type or not.

Things that we maybe still could add in this PR:

  • Add a dedicated AbstractMethodError instead of a regular Error with a 'Abstract method' message.
  • I found out the AdBuffet is never exposed somewhere so I was wondering if we can leave this class out and move this behavior into the VAST class.
  • If we look at our types strictly, the required properties of each class should be passed through the constructor because now a newly constructed instance will have uninitialized properties where the types define them as non-nullable.

@laurentdesmet
Copy link
Author

If this is merged, then I'll extend the codebase so the Wrapper instance has a reference to another VAST instance, which will be used in the async vast loader.

@timdp
Copy link
Member

timdp commented May 10, 2017

Add a dedicated AbstractMethodError instead of a regular Error with a 'Abstract method' message.

Definitely not against this. The main reason why we've been putting it off is because subclassing Error is messy, no matter how you do it.

I found out the AdBuffet is never exposed somewhere so I was wondering if we can leave this class out and move this behavior into the VAST class.

The spec defines it though. I kind of like to have it available as a concept, even if it's not immediately useful.

If we look at our types strictly, the required properties of each class should be passed through the constructor because now a newly constructed instance will have uninitialized properties where the types define them as non-nullable.

Yeah, I've been wondering what to do with the constructor vs. properties in general. I wouldn't be against passing a required options object into every constructor, as long as we also bump the major version, of course.

But maybe all of these things belong in separate PRs.

Before we merge this one, I just want to be absolutely sure that it's compatible with all our closed-source code (which I won't describe in detail because this discussion is public 😉).

@laurentdesmet
Copy link
Author

Jup, all makes sense.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling d780a94 on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0dd3441 on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling c230216 on add-flow-types into c042d6a on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling cca72d1 on add-flow-types into c042d6a on master.

@laurentdesmet
Copy link
Author

Ready for review again. Added support for shippable flow type definitions using flow-copy-source and added links between VAST and Wrappers which enable easy VAST tree walking.


gulp.task('watch', () => gulp.watch('src/**/*', ['build']))

gulp.task('doc:clean', () => del('docs'))
gulp.task('flow', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this async the only reason why you added stage-3 and the runtime transform, or is there another transitive dependency somewhere? If not, I'd just leave out the async because the end result will be the same. Also, maybe we want to drop Gulp altogether in favor of npm scripts?

`docs` directory.

Additionally, feel free to look at the source code. We recommend starting with
`src/index.js`, which should export all the classes you need.

## Typing

All APIs are statically typed using (flow)[https://flow.org]. Type checking is automatically performed when running `npm test`. You can also run type checking only by using the command `npm run flow`. Static typing adds an additional layer of defense against errors and can also improve the development experience by enabling autocompletion. For (atom.io)[https://atom.io], we recommend (Flow-IDE)[https://atom.io/packages/flow-ide].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave out the last two sentences and keep the readme lean and mean. It's not our job to educate people on static typing or to impose an editor.

@@ -22,12 +22,16 @@ const vast = new VAST()

Automatically generated API documentation can be found on
[GitHub Pages](https://zentrick.github.io/iab-vast-model/). You can also
open `docs/index.html` in a Web browser. Running `gulp doc` will (re)build the
open `docs/index.html` in a Web browser. Running `npm run doc` will (re)build the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not something to discuss under this PR, but I wonder why we have the docs on master rather than a separate gh-pages branch. There's quite a bit of static stuff here.

src/core/vast.js Outdated
* This will check if this VAST was wrapped and check if additional VAST
* wrappers should be loaded.
*/
followAdditionalWrappers (): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this isn't a getter?

@timdp timdp mentioned this pull request Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants