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

Commit 666ef6d

Browse files
jeffwhelpleyPatrickJS
authored andcommitted
fix(preboot): make user body exists (#328) and ensure replay when listen by attributes (#333)
1 parent 25a046b commit 666ef6d

File tree

13 files changed

+89
-103
lines changed

13 files changed

+89
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ test/coverage
4242
/typings/browser.d.ts
4343
/typings/main.d.ts
4444
/tsd_typings
45+
/docs

README.md

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,9 @@ Finally, once your client-side web app is "alive" it has to tell preboot that it
5151
to replay events.
5252

5353
```es6
54-
preboot.done();
54+
preboot.complete();
5555
```
5656

57-
## Examples
58-
59-
Server-side integrations:
60-
61-
* [Express](docs/examples.md#express)
62-
* [Hapi](docs/examples.md#hapi)
63-
* [Gulp](docs/examples.md#gulp)
64-
65-
Client-side integrations:
66-
67-
* [Angular 1.x](docs/examples.md#angular-1)
68-
* [Angular 2](docs/examples.md#angular-2)
69-
* [React](docs/examples.md#react)
70-
* [Ember](docs/examples.md#ember)
71-
72-
Custom strategies:
73-
74-
* [Listening for events](docs/examples.md#listen-strategy)
75-
* [Replaying events](docs/examples.md#replay-strategy)
76-
* [Freezing screen](docs/examples.md#freeze-strategy)
77-
7857
## Options
7958

8059
There are 5 different types of options that can be passed into preboot:
@@ -115,21 +94,3 @@ These are the names of global events that can affect the preboot workflow:
11594

11695
* `uglify` - You can always uglify the output of the client code stream yourself, but if you set this
11796
option to true preboot will do it for you.
118-
119-
## Play
120-
121-
If you want to play with this library you can clone it locally:
122-
123-
```sh
124-
git clone git@github.com:jeffwhelpley/preboot.git
125-
cd preboot
126-
gulp build
127-
gulp play
128-
```
129-
130-
Open your browser to http://localhost:3000. Make modifications to the options in build/task.build.js
131-
to see how preboot can be changed.
132-
133-
## Contributors
134-
135-
We would welcome any and all contributions. Please see the [Contributors Guide](docs/contributors.md).

buildtasks/docs_task.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var gulp = require('gulp');
2+
var typedoc = require('gulp-typedoc');
3+
4+
module.exports = function (opts) {
5+
gulp.task('docs', function() {
6+
return gulp.src(['src/**/*.ts'])
7+
.pipe(typedoc({
8+
9+
// typescript options
10+
module: 'commonjs',
11+
target: 'es5',
12+
includeDeclarations: true,
13+
14+
// typedoc options
15+
out: './docs',
16+
name: 'Preboot',
17+
theme: 'default',
18+
ignoreCompilerErrors: true,
19+
version: true
20+
}));
21+
});
22+
};

buildtasks/example_task.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ module.exports = function (opts) {
88
var exec = require('child_process').exec;
99
var distExampleDir = 'dist/example';
1010

11-
// need to clear out preboot in require cache for when we are watching
11+
// need to clear out preboot in require cache for when we are watching
1212
for (var key in require.cache) {
13-
if (key.indexOf(opts.distDir) >= 0) {
13+
if (require.cache.hasOwnProperty(key) && key.indexOf(opts.distDir) >= 0) {
1414
delete require.cache[key];
1515
}
1616
}
17-
17+
1818
// now pull in the latest preboot code
1919
var preboot = require(opts.prebootNode);
2020

buildtasks/test_task.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ var karma = require('karma');
88
module.exports = function (opts) {
99

1010
gulp.task('test', [
11-
'jasmine',
12-
'karma'
11+
'test.node',
12+
'test.browser'
1313
]);
1414

15-
gulp.task('jasmine', [ 'tsc' ], function () {
15+
gulp.task('test.node', [ 'tsc' ], function () {
1616
return gulp.src(opts.testFiles).
1717
pipe(jasmine({
1818
verbose: true,
@@ -37,7 +37,7 @@ module.exports = function (opts) {
3737
pipe(gulp.dest(karmaDest));
3838
});
3939

40-
gulp.task('karma', ['karma.build'], function (done) {
40+
gulp.task('test.browser', ['karma.build'], function (done) {
4141
var karmaCode = path.join(opts.distDir, 'karma/preboot_karma.js');
4242
var karmaConfig = {
4343
port: 9201,
@@ -61,7 +61,7 @@ module.exports = function (opts) {
6161
autoWatch: false,
6262
files: [karmaCode]
6363
};
64-
64+
6565
var server = new karma.Server(karmaConfig, done);
6666
return server.start();
6767
});

buildtasks/tsc_task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function (opts) {
99
var tsProject = typescript.createProject(tsConfig, {
1010
declaration: true
1111
});
12-
// TODO(gdi2290): missing declaration file stream
12+
1313
return tsProject.src().
1414
pipe(typescript(tsProject)).
1515
pipe(size()).

example/preboot_example.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<html>
2-
2+
33
<head>
44
<link rel="stylesheet" href="preboot.css">
55
<style>
66
.frmelem {
77
height: 50px; width: 50%; font-size: 24px; padding: 0 20px; margin: 20px 25%;
8-
}
8+
}
99
.frmbtn {
1010
height: 50px; width: 50%; font-size: 24px; margin: 20px 25%; text-align: center; z-index: 99999999999;
1111
}
1212
</style>
1313
<script src="preboot.js"></script>
1414
</head>
15-
15+
1616
<body>
1717
<app>
18-
<input class="frmelem" (keyup.enter)="enterEntered()" name="one">
18+
<input class="frmelem" preboot-events="keypress,keyup,keydown,input,change" (keyup.enter)="enterEntered()" name="one">
1919
<input class="frmelem" type="checkbox" name="blahCheck" value="foo">
2020
<input class="frmelem" type="radio" name="choo" value="val1">
2121
<input class="frmelem" type="radio" name="choo" value="val2">
@@ -69,4 +69,4 @@
6969
</script>
7070
</body>
7171

72-
</html>
72+
</html>

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,35 @@
2727
"express": "^4.13.4",
2828
"gulp-jasmine": "^2.3.0",
2929
"gulp-livereload": "^3.8.1",
30-
"gulp-size": "^2.0.0",
31-
"gulp-tslint": "^4.3.2",
30+
"gulp-size": "^2.1.0",
31+
"gulp-tslint": "^4.3.4",
32+
"gulp-typedoc": "^1.2.1",
3233
"gulp-typescript": "^2.12.1",
3334
"jasmine": "^2.4.1",
3435
"jasmine-reporters": "^2.1.1",
35-
"karma": "^0.13.21",
36-
"karma-browserify": "^5.0.2",
37-
"karma-chrome-launcher": "^0.2.2",
38-
"karma-jasmine": "^0.3.7",
36+
"karma": "^0.13.22",
37+
"karma-browserify": "^5.0.3",
38+
"karma-chrome-launcher": "^0.2.3",
39+
"karma-jasmine": "^0.3.8",
3940
"karma-phantomjs-launcher": "^1.0.0",
4041
"open": "0.0.5",
41-
"phantomjs-prebuilt": "^2.1.4",
42+
"phantomjs-prebuilt": "^2.1.7",
4243
"serve-static": "^1.10.2",
43-
"tslint": "^3.5.0",
44-
"typescript": "^1.8.7",
44+
"tslint": "^3.6.0",
45+
"typescript": "^1.8.9",
4546
"watchify": "^3.7.0"
4647
},
4748
"dependencies": {
48-
"gulp-insert": "^0.5.0",
49-
"vinyl-buffer": "^1.0.0",
50-
"vinyl-source-stream": "^1.1.0",
51-
"gulp-rename": "^1.2.2",
52-
"gulp-uglify": "^1.5.3",
5349
"browserify": "^13.0.0",
5450
"event-stream": "^3.3.2",
5551
"gulp": "^3.9.1",
56-
"lodash": "^4.5.1",
57-
"q": "^1.4.1"
52+
"gulp-insert": "^0.5.0",
53+
"gulp-rename": "^1.2.2",
54+
"gulp-uglify": "^1.5.3",
55+
"lodash": "^4.7.0",
56+
"q": "^1.4.1",
57+
"vinyl-buffer": "^1.0.0",
58+
"vinyl-source-stream": "^1.1.0"
5859
},
5960
"repository": {
6061
"type": "git",

src/browser/preboot_browser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let state = {
3333
};
3434

3535
/**
36-
* Once bootstrap has compled, we replay events,
36+
* Once bootstrap has completed, we replay events,
3737
* switch buffer and then cleanup
3838
*/
3939
export function complete() {
@@ -80,7 +80,7 @@ function load() {
8080

8181
// start listening to events
8282
eventManager.startListening(preboot, opts);
83-
};
83+
}
8484

8585
/**
8686
* Resume the completion process; if complete already called,
@@ -120,7 +120,8 @@ export function start() {
120120
dom.init({ window: window });
121121

122122
// if body there, then run load handler right away, otherwise register for onLoad
123-
dom.state.body ? load() : dom.onLoad(load);
123+
let bodyExists = dom.state.body && Object.keys(dom.state.body).length;
124+
bodyExists ? load() : dom.onLoad(load);
124125

125126
// set up other handlers
126127
dom.on(opts.pauseEvent, () => state.canComplete = false);

src/node/browser_code_generator.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const Q = require('q');
2-
const uglify = require('gulp-uglify');
3-
const insert = require('gulp-insert');
4-
const rename = require('gulp-rename');
5-
const eventStream = require('event-stream');
6-
const buffer = require('vinyl-buffer');
7-
const source = require('vinyl-source-stream');
8-
const browserify = require('browserify');
1+
import * as Q from 'q';
2+
import * as rename from 'gulp-rename';
3+
import * as uglify from 'gulp-uglify';
4+
import * as insert from 'gulp-insert';
5+
import * as eventStream from 'event-stream';
6+
import * as buffer from 'vinyl-buffer';
7+
import * as source from 'vinyl-source-stream';
8+
import * as browserify from 'browserify';
99
import {normalize, listenStrategies, replayStrategies, freezeStrategies} from './normalize';
1010
import {stringifyWithFunctions} from './utils';
1111
import {PrebootOptions} from '../interfaces/preboot_options';
@@ -20,7 +20,7 @@ export let browserCodeCache = {};
2020
* attributes strategies will be stubbed out (meaing the refs will be {})
2121
*/
2222
export function ignoreUnusedStrategies(
23-
b: any/*Browserify.BrowserifyObject*/,
23+
b: any, /*Browserify.BrowserifyObject*/
2424
bOpts: Object,
2525
strategyOpts: any[],
2626
allStrategies: Object,

0 commit comments

Comments
 (0)