Skip to content

Commit f8138ba

Browse files
committed
chore(build): Merge in upstream changes on build. Remove Symbol.observable
1 parent 3be3ad8 commit f8138ba

File tree

2 files changed

+63
-117
lines changed

2 files changed

+63
-117
lines changed

src/firestore/firestore.ts

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ import 'rxjs/add/operator/map';
88
import { Injectable } from '@angular/core';
99
import { FirebaseApp } from 'angularfire2';
1010

11-
/**
12-
* Bring in the types for Symbol.observable. Appending
13-
* Symbole.observable to the prototype allows us to turn
14-
* references into Observables.
15-
*/
16-
declare global {
17-
export interface SymbolConstructor {
18-
readonly observable: symbol;
19-
}
20-
}
21-
2211
// A convience type for making a query.
2312
// Example: const query = (ref) => ref.where('name', == 'david');
2413
export type QueryFn = (ref: CollectionReference) => Query;
@@ -249,37 +238,6 @@ export class AngularFirestoreDocument<T> implements ArrayLike<T> {
249238
return (snap.exists ? snap.data() : null) as T;
250239
});
251240
}
252-
253-
/**
254-
* Provide the ability to create an Observable from this reference. The
255-
* underlying reference's onSnapshot() method is compatible with rxjs's
256-
* observer pattern. The method needs to return an object that maps an
257-
* Observable's subscribe() method to onSnapshot().
258-
*
259-
* Unlike valueChanges(), this observable automatically unwraps the snapshot
260-
* returning to you an observable of the type you provided.
261-
*
262-
* Note: We are currently checking data.exists and returning null if the
263-
* document does not exist. Firestore will throw if you call snap.data()
264-
* on a non-existent document. We are converting to null to provide
265-
* flexibility in the view template.
266-
*/
267-
[Symbol.observable]() {
268-
const ref = this.ref;
269-
return {
270-
subscribe(observer) {
271-
const unsubscribe = ref.onSnapshot((snap) => {
272-
try {
273-
const unwrapped = snap.exists ? snap.data() : null;
274-
observer.next(unwrapped as T);
275-
} catch (e) {
276-
observer.error(e);
277-
}
278-
}, observer.error, observer.complete);
279-
return { unsubscribe };
280-
}
281-
}
282-
}
283241
}
284242

285243
/**
@@ -307,12 +265,7 @@ export class AngularFirestoreDocument<T> implements ArrayLike<T> {
307265
* // OR! Avoid unwrapping and transform from an Observable
308266
* Observable.from(fakeStock).subscribe(value => console.log(value));
309267
*/
310-
export class AngularFirestoreCollection<T> implements ArrayLike<T> {
311-
// TODO(davideast): Remove these properties once TypeScript is down with Observable.from
312-
// These are totally useless and are used to appease TypeScript.
313-
public length: number;
314-
[n: number]: T;
315-
268+
export class AngularFirestoreCollection<T> {
316269
/**
317270
* The contstuctor takes in a CollectionReference and Query to provide wrapper methods
318271
* for data operations, data streaming, and Symbol.observable.
@@ -366,31 +319,4 @@ export class AngularFirestoreCollection<T> implements ArrayLike<T> {
366319
doc(path: string) {
367320
return new AngularFirestoreDocument(this.ref.doc(path));
368321
}
369-
370-
/**
371-
* Provide the ability to create an Observable from this reference. The
372-
* underlying reference's onSnapshot() method is compatible with rxjs's
373-
* observer pattern. The method needs to return an object that maps an
374-
* Observable's subscribe() method to onSnapshot().
375-
*
376-
* Unlike valueChanges(), this observable automatically unwraps the snapshot
377-
* returning to you an observable of the type you provided.
378-
*
379-
* Note: We are currently checking data.exists and returning null if the
380-
* document does not exist. Firestore will throw if you call snap.data()
381-
* on a non-existent document. We are converting to null to provide
382-
* flexibility in the view template.
383-
*/
384-
[Symbol.observable] () {
385-
const query = this.query;
386-
return {
387-
subscribe(subscriber: Subscriber<T[]>) {
388-
const unsubscribe = query.onSnapshot((snap: QuerySnapshot) => {
389-
const records = snap.docs.map(docs => docs.data()) as T[];
390-
subscriber.next(records);
391-
}, subscriber.error, subscriber.complete);
392-
return { unsubscribe };
393-
}
394-
}
395-
}
396322
}

tools/build.js

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { rollup } = require('rollup');
22
const { spawn } = require('child_process');
33
const { Observable } = require('rxjs');
4-
const { copy, readFileSync, writeFile } = require('fs-extra');
4+
const { copy, readFileSync, writeFile, statSync } = require('fs-extra');
55
const { prettySize } = require('pretty-size');
66
const gzipSize = require('gzip-size');
77
const resolve = require('rollup-plugin-node-resolve');
@@ -29,6 +29,18 @@ const GLOBALS = {
2929
'rxjs/operator/take': 'Rx.Observable.prototype',
3030
'rxjs/operator/toArray': 'Rx.Observable.prototype',
3131
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
32+
'rxjs/add/operator/map': 'Rx.Observable.prototype',
33+
'rxjs/add/operator/scan': 'Rx.Observable.prototype',
34+
'rxjs/add/operator/skip': 'Rx.Observable.prototype',
35+
'rxjs/add/operator/do': 'Rx.Observable.prototype',
36+
'rxjs/add/operator/filter': 'Rx.Observable.prototype',
37+
'rxjs/add/operator/skipUntil': 'Rx.Observable.prototype',
38+
'rxjs/add/operator/skipWhile': 'Rx.Observable.prototype',
39+
'rxjs/add/operator/withLatestFrom': 'Rx.Observable.prototype',
40+
'rxjs/add/observable/merge': 'Rx.Observable',
41+
'rxjs/add/operator/delay': 'Rx.Observable',
42+
'rxjs/add/operator/debounce': 'Rx.Observable',
43+
'rxjs/observable/fromEvent': 'Rx.Observable',
3244
'rxjs/operator': 'Rx.Observable.prototype',
3345
'@angular/core': 'ng.core',
3446
'@angular/compiler': 'ng.compiler',
@@ -41,6 +53,7 @@ const GLOBALS = {
4153
'angularfire2': 'angularfire2',
4254
'angularfire2/auth': 'angularfire2.auth',
4355
'angularfire2/database': 'angularfire2.database',
56+
'angularfire2/database-deprecated': 'angularfire2.database_deprecated',
4457
'angularfire2/firestore': 'angularfire2.firestore'
4558
};
4659

@@ -54,6 +67,38 @@ const VERSIONS = {
5467
FIRESTORE_VERSION: pkg.dependencies['firestore']
5568
};
5669

70+
const MODULE_NAMES = {
71+
core: 'angularfire2',
72+
auth: 'angularfire2.auth',
73+
database: 'angularfire2.database',
74+
"database-deprecated": 'angularfire2.database_deprecated',
75+
firestore: 'angularfire2.firestore'
76+
};
77+
78+
const ENTRIES = {
79+
core: `${process.cwd()}/dist/packages-dist/index.js`,
80+
auth: `${process.cwd()}/dist/packages-dist/auth/index.js`,
81+
database: `${process.cwd()}/dist/packages-dist/database/index.js`,
82+
"database-deprecated": `${process.cwd()}/dist/packages-dist/database-deprecated/index.js`,
83+
firestore: `${process.cwd()}/dist/packages-dist/firestore/index.js`
84+
};
85+
86+
const SRC_PKG_PATHS = {
87+
core: `${process.cwd()}/src/core/package.json`,
88+
auth: `${process.cwd()}/src/auth/package.json`,
89+
database: `${process.cwd()}/src/database/package.json`,
90+
"database-deprecated": `${process.cwd()}/src/database-deprecated/package.json`,
91+
firestore: `${process.cwd()}/src/firestore/package.json`
92+
};
93+
94+
const DEST_PKG_PATHS = {
95+
core: `${process.cwd()}/dist/packages-dist/package.json`,
96+
auth: `${process.cwd()}/dist/packages-dist/auth/package.json`,
97+
database: `${process.cwd()}/dist/packages-dist/database/package.json`,
98+
"database-deprecated": `${process.cwd()}/dist/packages-dist/database-deprecated/package.json`,
99+
firestore: `${process.cwd()}/dist/packages-dist/firestore/package.json`
100+
};
101+
57102
// Constants for running typescript commands
58103
const TSC = 'node_modules/.bin/tsc';
59104
const NGC = 'node_modules/.bin/ngc';
@@ -70,7 +115,7 @@ function spawnObservable(command, args) {
70115
const cmd = spawn(command, args);
71116
observer.next(''); // hack to kick things off, not every command will have a stdout
72117
cmd.stdout.on('data', (data) => { observer.next(data.toString('utf8')); });
73-
cmd.stderr.on('data', (data) => { observer.error(data.toString('utf8')); });
118+
cmd.stderr.on('data', (data) => { console.log(data); observer.error(data.toString('utf8')); });
74119
cmd.on('close', (data) => { observer.complete(); });
75120
});
76121
}
@@ -95,18 +140,6 @@ function generateBundle(entry, { dest, globals, moduleName }) {
95140
*/
96141
function createUmd(name, globals) {
97142
// core module is angularfire2 the rest are angularfire2.feature
98-
const MODULE_NAMES = {
99-
core: 'angularfire2',
100-
auth: 'angularfire2.auth',
101-
database: 'angularfire2.database',
102-
firestore: 'angularfire2.firestore'
103-
};
104-
const ENTRIES = {
105-
core: `${process.cwd()}/dist/packages-dist/index.js`,
106-
auth: `${process.cwd()}/dist/packages-dist/auth/index.js`,
107-
database: `${process.cwd()}/dist/packages-dist/database/index.js`,
108-
firestore: `${process.cwd()}/dist/packages-dist/firestore/index.js`,
109-
};
110143
const moduleName = MODULE_NAMES[name];
111144
const entry = ENTRIES[name];
112145
return generateBundle(entry, {
@@ -131,27 +164,15 @@ function createTestUmd(globals) {
131164
* @param {string} moduleName
132165
*/
133166
function getSrcPackageFile(moduleName) {
134-
const PATHS = {
135-
core: `${process.cwd()}/src/core/package.json`,
136-
auth: `${process.cwd()}/src/auth/package.json`,
137-
database: `${process.cwd()}/src/database/package.json`,
138-
firestore: `${process.cwd()}/src/firestore/package.json`
139-
};
140-
return PATHS[moduleName];
167+
return SRC_PKG_PATHS[moduleName];
141168
}
142169

143170
/**
144171
* Get the file path of the dist package.json for a module
145172
* @param {string} moduleName
146173
*/
147174
function getDestPackageFile(moduleName) {
148-
const PATHS = {
149-
core: `${process.cwd()}/dist/packages-dist/package.json`,
150-
auth: `${process.cwd()}/dist/packages-dist/auth/package.json`,
151-
database: `${process.cwd()}/dist/packages-dist/database/package.json`,
152-
firestore: `${process.cwd()}/dist/packages-dist/firestore/package.json`
153-
};
154-
return PATHS[moduleName];
175+
return DEST_PKG_PATHS[moduleName];
155176
}
156177

157178
/**
@@ -200,10 +221,9 @@ function copyReadme() {
200221
function measure(module) {
201222
const path = `${process.cwd()}/dist/packages-dist/bundles/${module}.umd.js`;
202223
const file = readFileSync(path);
203-
const bytes = gzipSize.sync(file);
204-
const gzipped = prettySize(bytes, true);
205-
const regular = prettySize(bytes);
206-
return { regular, gzipped };
224+
const gzip = prettySize(gzipSize.sync(file), true);
225+
const size = prettySize(statSync(path).size, true);
226+
return { size, gzip };
207227
}
208228

209229
/**
@@ -251,12 +271,12 @@ function buildModules(globals) {
251271
const core$ = buildModule('core', globals);
252272
const auth$ = buildModule('auth', globals);
253273
const db$ = buildModule('database', globals);
254-
const afs$ = buildModule('firestore', globals);
274+
const firestore$ = buildModule('firestore', globals);
255275
return Observable
256276
.forkJoin(core$, Observable.from(copyRootTest()))
257277
.switchMapTo(auth$)
258278
.switchMapTo(db$)
259-
.switchMapTo(afs$);
279+
.switchMapTo(firestore$);
260280
}
261281

262282
function buildLibrary(globals) {
@@ -267,15 +287,15 @@ function buildLibrary(globals) {
267287
.switchMap(() => Observable.from(copyNpmIgnore()))
268288
.switchMap(() => Observable.from(copyReadme()))
269289
.do(() => {
270-
const core = measure('core');
271-
const auth = measure('auth');
272-
const database = measure('database');
273-
const firestore = measure('firestore');
290+
const coreStats = measure('core');
291+
const authStats = measure('auth');
292+
const dbStats = measure('database');
293+
const fsStats = measure('firestore');
274294
console.log(`
275-
core.umd.js - ${core.regular}, ${core.gzipped}
276-
auth.umd.js - ${auth.regular}, ${auth.gzipped}}
277-
database.umd.js - ${database.regular}, ${database.gzipped}}
278-
firestore.umd.js - ${firestore.regular}, ${firestore.gzipped}}
295+
core.umd.js - ${coreStats.size}, ${coreStats.gzip}
296+
auth.umd.js - ${authStats.size}, ${authStats.gzip}
297+
database.umd.js - ${dbStats.size}, ${dbStats.gzip}
298+
firestore.umd.js - ${fsStats.size}, ${fsStats.gzip}
279299
`);
280300
verifyVersions();
281301
});

0 commit comments

Comments
 (0)