UNPKG

2.93 kBMarkdownView Raw
1varsnap.js
2==========
3
4[![Codeship Status for albertyw/varsnap.js](https://app.codeship.com/projects/772d6dd0-7616-0137-b181-4a74f06c083c/status?branch=master)](https://app.codeship.com/projects/349777)
5
6[Javascript Varsnap Client](https://www.varsnap.com/). For use in both browser and node.js
7
8Installation
9------------
10
11Install from NPM - `npm install --save varsnap`
12
13Configuration
14-------------
15
16The varsnap decorator needs to be configured with a `config` object with these variables:
17
18 - `varsnap` - Should be either `true` or `false`. Varsnap will be disabled if the variable is anything other than `true`.
19 - `env` - If set to `development`, the client will receive events from production. If set to `production`, the client will emit events.
20 - `producerToken` - Only clients with this token may emit production snapshots. Copied from https://www.varsnap.com/user/
21 - `consumerToken` - Only clients with this token may emit development snapshots. Copied from https://www.varsnap.com/user/
22
23If you're deploying varsnap to a browser, note that Varsnap needs unmangled code in production to work correctly.
24
25Usage
26-----
27
28Wrap your functions with the varsnap decorator for any function you'd like to make better:
29
30```javascript
31// Node.js
32var varsnap = require('varsnap');
33
34// Browser
35var varsnap = window.varsnap;
36
37// Configuration
38varsnap.updateConfig({
39 varsnap: true,
40 env: 'production',
41 producerToken: 'producer-abcd'
42});
43
44// Integration
45function example(x, y, z) {
46 // ...
47}
48example = varsnap(example);
49
50example(1, 2, 3);
51```
52
53See `example/example.js` for example usage.
54
55Typescript
56----------
57If you are using typescript, make sure your `tsconfig.json` has a `"target"` to `"es2015"`, `"es6"`, or later.
58This is needed to persist function names after compiling to javascript.
59See https://github.com/microsoft/TypeScript/issues/5611 for details.
60
61Testing
62-------
63
64Use the `varsnap.runTests()` function.
65
66```javascript
67function test() {
68 const status = varsnap.runTests().then(function(status) => {
69 console.assert(status);
70 });;
71}
72```
73
74If you are using [mocha](https://mochajs.org/) and [chai](https://www.chaijs.com/),
75you can include this test script:
76
77```javascript
78const expect = require('chai').expect;
79const varsnap = require('varsnap');
80
81// Load the modules where varsnap is being used
82require('./example');
83
84context('Varsnap', function() {
85 this.timeout(30 * 1000);
86 it('runs with production', function() {
87 return varsnap.runTests().then(status => {
88 expect(status).to.be.true;
89 });
90 });
91});
92```
93
94See `example/test.js` for example usage.
95
96Release
97-------
98
991. Update Changelog with new version
1002. Update `const version` in `varsnap/core.ts`
1013. Update package.json version and run `npm install`
1024. Update `.uglify.json` and `.uglify.min.json`
1035. Run `npm run package`
1046. Git commit and tag
1057. `npm publish`
1068. Upload `dist/*` to https://github.com/albertyw/varsnap.js/releases