Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Collapsify ❤️ Reactivity #24

Closed
wants to merge 12 commits into from
Closed

Collapsify ❤️ Reactivity #24

wants to merge 12 commits into from

Conversation

terinjokes
Copy link
Contributor

CP-48 requires better communication between the Collapsify service and our internal processes to be able to give better error messages to users. The crux of this branch rests upon this requirement.

Instead of utilizing Promises to their full potential, the base branch would very quickly "catch" the failing Promises returned by the HTTP library and return a resolved Promise containing an empty Buffer. The rest of the service was centered on this behavior. :person_frowning:

This pull request refactors Collapsify onto the reactive model proposed by Reactive Extensions, and RxJS, and ensures standardized errors are returned by the Collapsify service in such a way that a client can understand the cause of the error.

}

if (res.statusCode >= 400) {
return observer.onError(new (errors.find(res.statusCode))('HTTP ' + res.statusCode + ': ' + url));
Copy link

Choose a reason for hiding this comment

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

url should be currentURL or else it'll reference the import.

@dotjs
Copy link
Contributor

dotjs commented Jul 2, 2015

Tests, tests and more test required.

@dotjs
Copy link
Contributor

dotjs commented Jul 2, 2015

Implement observable for startkeyframerule event.

@terinjokes
Copy link
Contributor Author

@dotjs woot! this last commit finally splits the flatteners logic into separate files.

Implemented HttpClient with needle and RxJS. Uses RxJS's recursive scheduler to
handle HTTP redirects following the "forbidden" configuration.

Knock-on affects throughout Collapsify to account for RxJS's Observables, for
now merely being converted into Bluebird promises.

The HTTP server returns JSON for errors, along with 5xx series status codes.
The CLI sets an appropriate exit code.
Use the `errors` module to help standardize created errors. This allows custom
errors to be defined in a single place, including a "code" property.

The server has been modified to return JSON on 200 responses.
Collapsify previously assumed all requests were valid, and simply looked
at the "url" query parameter on the request, with no respect giving to
the path.

This adds routes to the HTTP server implementation, which I use to
enforce path and method restrictions.

I'm also using this oppurtunity to implement two routes for collapsing
a resource: the continued legacy "GET /?url=" and a new "POST
/v1/collapse" with a JSON body containing a "url" property. The GET
route continues to return an HTML response, whereas the new POST route
returns a JSON response.

The GET route is now deprecated.
Remove the manual Promise queues, "compilationQueue" and "elementQueue", and
implemented them "automatically" with Observables. That is, RxJS and the
computer can keep Observables in order, even when their values may be
asynchronous.

By using "reply", we can turn a hot observable into a cold observable, with the
effect of starting these asynchronous actions, even before there's an attached
subscriber to the returned observable.
The tags 'startkeyframesrule' and 'endkeygramesrule' were previously
being ignored and dropped when flattening stylesheets.
Remove the manual Promise queues, "compilationQueue" and "elementQueue", and
implemented them with Observables.

CollapsifyDOMHandler is a custom htmlparser2 handler that generates Hot
Observables once the `parse` method of htmlparser2's Parser is called.
This is converted to a Cold Observable with "replay".
…epalive

The HTTP client was getting "socket hang up" errors, and long pauses in
responses, that seemed to be caused by an incorrect handling of open
sockets in a connection pool.

`yakaa` is an improved HTTP agent, specifically for keepalive sockets.
However, `needle` doesn't seem to be using it properly, so it was
replaced with `bhttp`.
Breaking all BDD rules, adding unit tests for the flatteners and
HttpClient, testing that they seem to collapse resources while
preserving errors, and that they seem to have the neccessary
interdependencies required.
@terinjokes terinjokes deleted the rx branch April 8, 2016 20:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants