-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration to Typescript #169
Conversation
First off, thanks for the PR! This is a ton of work, and we're grateful for your contributions :) I think the best way to handle this (ideally the fastest time to merge) is going to be as follows:
I expect the first to be pretty straightforward, though I assume there will be questions around how this will be packaged, what versioning looks like, etc. Moving it somewhere other than master will let us get it into the repo and handle the packaging work without blocking the contribution. I expect the second to be contentious for a few reasons:
|
Hey mcdonamp, thank you for the detailed reply. I'll take your advice and break this up so we start with just a PR for Typescript support. I'm assuming I can just reuse this PR for a TS PR, so I'll update this over the weekend. |
@jshcrowthe I updated the code to best represent the suggestions made by @mcdonamp (Thank you guys for taking the time to look through this!) |
Awesome! I will take a look. Thanks so much! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MichaelSolati!
Just wanted to make sure you know I'm in process of reviewing this (lots going on 😄). Starting at the top level (i.e. build/test/packaging stuff) had a couple of points of feedback (figured I'd give them in batches):
-
First and foremost, the committed
package-lock.json
caused my NPM install to fail w/ some proxy
issue.npm ERR! code ENOTFOUND npm ERR! errno ENOTFOUND npm ERR! network request to https://registry.npmjs.org/ts-node/-/ts-node-5.0.1.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443 npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config'
Had to delete it and rerun
npm install
to get the dependencies set up. -
Add a
typings
field to thepackage.json
to ensure that users of the package get the benefits of the generated type definitions. -
Add a
prepare
script to thepackage.json
scripts section that will ensure this package gets built properly before release. (See https://docs.npmjs.com/misc/scripts on theprepare
script) -
Output an
ESM
module build in addition toUMD
/CJS
. -
I'd suggest, instead of rolling your own build system using NPM scripts (e.g.
rm -rf ./dist && tsc && npm run browserify && npm run uglify
) that you use a build system like gulp, or a bundler like rollup. (Full disclosure we just migrated the firebase-js-sdk to a rollup based build system and I think you could re-use one ofrollup.config.js
files with very few edits here.) -
We have a
travis
script in thepackage.json
that isn't used anywhere. Do we need that? -
In the
travis.yml
what was the rationale behind runningnpm run build
after the tests have passed? -
We don't actually run our tests in real browsers, is it possible to get something up and running w/ a browser test runner?
-
Does it make sense to set the
importHelpers
flag in ourtsconfig.json
and usetslib
? -
The
lib
property in thetsconfig.json
is set toes2016
, what was the intended browser support matrix here (I don't see us loading polyfills/shims anywhere)?
Figure I'll submit this here, more to come!
@jshcrowthe perhaps the most critical code review I've ever received, but I do appreciate it. Some of the choices I made aren't necessarily justified, so I spend the weekend polishing up based on your feedback. 😁 |
@jshcrowthe I'm 99% confident I made changes based on every point you raised. I also tested it with a personal project and everything seems to be working correctly with the new build, and it passes the tests still. I did try using the current version of The only thing I couldn't get to (and am not sure if I can with time and other things on my plate), was looking into setting up a browser test runner. Hopefully that won't be an issue. |
@jshcrowthe just wanted to bump this and see if there was any update to the status of this PR? |
Hey @MichaelSolati appreciate the ping! I will go over this in the next few days and get back to you 😄 |
Any update on this? Hoping to continue to use geoFire with Angular6 Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MichaelSolati great work here things are looking really good. I have added some specific things inline if you could address those that'd be great.
rollup.config.js
Outdated
const completeBuilds = [{ | ||
input: 'src/index.ts', | ||
output: [{ | ||
file: pkg.browser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are shipping both a pkg.browser
and a pkg.main
that are both builds of the same file. Since this package doesn't require a Node/Browser specific entrypoint, let's remove the pkg.browser
build from here and the package.json
Note: See https://github.com/jshcrowthe/howto-browser-modules for details
src/geoFire/index.ts
Outdated
import * as firebase from 'firebase'; | ||
|
||
import { GeoQuery } from './geoQuery'; | ||
import { decodeGeoFireObject, degreesToRadians, distance, encodeGeoFireObject, encodeGeohash, validateLocation, validateKey } from './geoFireUtils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: It seems as though we don't use degreesToRadians
src/geoFire/geoFireUtils.ts
Outdated
* @param newQueryCriteria The criteria which specifies the query's center and/or radius. | ||
* @param requireCenterAndRadius The criteria which center and radius required. | ||
*/ | ||
export function validateCriteria(newQueryCriteria: any, requireCenterAndRadius: boolean = false): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently use the any
type for newQueryCriteria
here. It seems like we could probably provide an interface to help users input the proper object here.
src/geoFire/geoFireUtils.ts
Outdated
* @param A Firestore snapshot. | ||
* @returns The Firestore snapshot's id. | ||
*/ | ||
export function geoFirestoreGetKey(snapshot: firebase.firestore.DocumentSnapshot): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fxn is unused. Probably part of the 2nd half of your original PR?
src/geoFire/geoFireUtils.ts
Outdated
* @returns The Firebase snapshot's key. | ||
*/ | ||
export function geoFireGetKey(snapshot: firebase.database.DataSnapshot): string { | ||
let key: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like part of the function body was removed here (specifically the handling of snapshot.key
fxn and a fallback snapshot.name
.
What was the rationale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize that those were supported keys/attributes in older version of Firebase. I was basing it off of the typing from Firebase 4.13.1. Anyway I'll be adding it back in.
src/geoFire/geoQuery.ts
Outdated
private _cancelled: boolean = false; | ||
private _center: number[]; | ||
// A dictionary of geohash queries which currently have an active callbacks | ||
private _currentGeohashesQueried: any = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably provide an interface here as well. This should really be a map of string to the object here no?
}); | ||
|
||
// Add the geohash query to the current geohashes queried dictionary and save its state | ||
this._currentGeohashesQueried[toQueryStr] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets define an interface for this object.
src/geoFire/geoQuery.ts
Outdated
// Add the geohash query to the current geohashes queried dictionary and save its state | ||
this._currentGeohashesQueried[toQueryStr] = { | ||
active: true, | ||
childAddedCallback: childAddedCallback, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Duplicating the key/val here is unnecessary. The following would work no?
this._currentGeohashesQueried[toQueryStr] = {
active: true,
childAddedCallback,
childRemovedCallback,
childChangedCallback,
valueCallback
};
src/geoFire/geoQuery.ts
Outdated
private _currentGeohashesQueried: any = {}; | ||
// A dictionary of locations that a currently active in the queries | ||
// Note that not all of these are currently within this query | ||
private _locationsTracked: any = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's type this as well please.
isInQuery = (distanceFromCenter <= this._radius); | ||
|
||
// Add this location to the locations queried dictionary even if it is not within this query | ||
this._locationsTracked[key] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, we should provide an interface for this type, and we can remove the duplication of identical key/val here.
@jshcrowthe I think and/or hope I hit all the points you mentioned. I was trying to keep it pretty much how the old JS version was, however I definitely agree with a lot of the changes you have suggested! (Especially the use of Maps). The Maps did provide a small issue... I was hoping I could skip the turning the keys into an Array, and just iterate through the Map (there were a few places where that wouldn't have been appropriate, however for the most part it should have been fine). And while that did work and passed the tests, I did also get this weird error:
I opted to turn the keys into an Array to avoid that weirdness... |
I may have lead you astray slightly with the use of the word i.e. const object: { [name: string]: SomeInterface } = { ... }; My apologies for the confusion. I'll go through the rest of the changes. |
Ah... Well... Shucks! It seems to work fine anyway, and to be honest, I kind of prefer it. So no harm no fowl! 🐔 (Yes... Chicken puns...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaelSolati I think we are close here, thanks again for the hard work.
I left a couple comments inline. Additionally, using the Map
collection and the Array.from
syntax enforces ES2015 compatibility (unless we are going to polyfill for this lib, which I don't think we want?). Also, using the Map
collection for string based keys is really a waste IMO.
Let's revert the Object -> Map refactor (but please include the Object version of the needed annotations).
@@ -0,0 +1,6 @@ | |||
export interface GeoQueryCallbacks { | |||
ready: any[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In src/geoFire/interfaces/geoQueryState.ts
we have this interface:
(a: firebase.database.DataSnapshot, b?: string) => any
If this is the callback type could we name it and instead of an any[]
use that?
Ditto for the 3 props below
|
||
export interface GeoQueryState { | ||
active: boolean; | ||
childAddedCallback: (a: firebase.database.DataSnapshot, b?: string) => any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we could not repeat ourselves here with the callback signature. No?
Also, could we be more descriptive with the prop names than a
and b
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it may not be necessary, I'm not sure what a better/ideal solution would be. Effectively I can change it to whatever you thing is best. I'm just not sure what it would be off of the top of my head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets just create a type and assign each of these to that?
export type GeoQueryStateCallback = (a: firebase.database.DataSnapshot, b?: string) => any;
export interface GeoQueryState {
childAddedCallback: GeoQueryStateCallback;
...
}
As far as the property names go, I just looked at our .d.ts for the typescript package and we use the same variable names so I guess we are probably fine with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good, one last thing and then I think we are good to go!
|
||
export interface GeoQueryState { | ||
active: boolean; | ||
childAddedCallback: (a: firebase.database.DataSnapshot, b?: string) => any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets just create a type and assign each of these to that?
export type GeoQueryStateCallback = (a: firebase.database.DataSnapshot, b?: string) => any;
export interface GeoQueryState {
childAddedCallback: GeoQueryStateCallback;
...
}
As far as the property names go, I just looked at our .d.ts for the typescript package and we use the same variable names so I guess we are probably fine with that.
@jshcrowthe done! Tests are running, and after your approval I think I'm going to get a beer. |
Great work here @MichaelSolati! |
Hey, @jshcrowthe, can we get a new Thanks! |
It's been over 6 months since this PR was merged but there has been no new release on NPM. This project seems to be basically abandoned. I get that no new dev work is going to happen here, but it would be great if at the very least someone could take the time to simply publish a new release on NPM based on this already-merged code. @mikelehen, you seem to be active in reviewing/merging some of the recent PRs in the |
Josh left Google, so I assume that's why it's been dropped. I'll make sure it gets picked up and released. |
Shucks... @mcdonamp I may ask for a little time to make some fixes/tweaks before you guys publish again. I've learned a lot while working on a diff firebase library and there are some things that should get addressed before a launch. I'll get on it and have a PR open by the end of the month. |
Hey, let me know when you are done with the change. I will publish it to npm. |
I'm pleased to see that my comment from yesterday may have kickstarted some momentum back into this project, but at least for me personally I would really prefer to see a new release published as soon as possible. The current version of the code has been working well, but I keep getting these @Feiyang1, can we get a |
I can certainly publish a beta release and you can get it using geofire-js@next. Would it work for you? |
Beta version published! https://www.npmjs.com/package/geofire?activeTab=dependents |
Description
This is essentially a conversion of the package to Typescript while also bumping Firebase support to v4.x.x.
Fixes #98