Comparing version 0.1.10 to 0.1.11
{ | ||
"name": "braidify", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "Synchronization for the Web (reference implementation)", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# Braidify Library | ||
Easily adds Braid to existing Javascript libraries. | ||
Easily adds Braid to existing Javascript code. | ||
@@ -9,4 +9,10 @@ - [npm package](https://www.npmjs.com/package/braidify) now available for testing | ||
Today it has wrappers for the following HTTP libraries: | ||
### Purpose | ||
Just as Braid is "a few simple extensions to HTTP" that add synchronization, | ||
the `braidify` library is "a few simple extensions to HTTP libraries" that | ||
add synchronization to your HTTP code. | ||
Supports the following HTTP libraries: | ||
```javascript | ||
@@ -17,5 +23,5 @@ require('braidify').fetch // Browser fetch() API and require('node-fetch') | ||
And we'd love to add Braid support to any other http API you like. | ||
We would love to support your favorite library, too. | ||
Let's look at some examples: | ||
Let's look at some examples of using it: | ||
@@ -98,15 +104,15 @@ ### Browser `fetch()` | ||
function connect () { | ||
fetch('https://localhost:3009/chat', | ||
{subscribe: {keep_alive: true}}).andThen( | ||
x => console.log('Got ', x) | ||
//x => {throw new Error('hi')} | ||
).catch(e => { | ||
console.error('Reconnecting!', e); | ||
setTimeout(connect, 1000) | ||
}) | ||
} | ||
connect() | ||
fetch('https://localhost:3009/chat', | ||
{subscribe: {keep_alive: true}}).andThen( | ||
x => console.log('Got ', x) | ||
) | ||
``` | ||
Note: the current version of `node-fetch` doesn't properly throw errors when a | ||
response connection dies, and thus you cannot attach a `.catch()` handler to | ||
automatically reconnect. (See | ||
[issue #980](https://github.com/node-fetch/node-fetch/issues/980) and | ||
[#753](https://github.com/node-fetch/node-fetch/issues/753).) We recommend | ||
using the `http` library (below) for requests on nodejs instead. | ||
## Nodejs client with `require('http')` | ||
@@ -120,4 +126,4 @@ | ||
// or: | ||
// import {http} from 'braidify' | ||
// https = http(require('https')) | ||
// import braidify from 'braidify' | ||
// https = braidify.http(require('https')) | ||
@@ -168,2 +174,4 @@ https.get( | ||
var braidify = require('braidify').http_server | ||
// or: | ||
import {http_server as braidify} from 'braidify' | ||
@@ -212,2 +220,4 @@ // Braidify will give you these fields and methods: | ||
var braidify = require('braidify').http_server | ||
// or: | ||
import {http_server as braidify} from 'braidify' | ||
@@ -214,0 +224,0 @@ require('http').createServer( |
36008
238