Skip to content
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

refactor(database): classes for typescript database implementation #55

Merged
merged 3 commits into from
Jun 17, 2017

Conversation

jsayol
Copy link
Contributor

@jsayol jsayol commented Jun 15, 2017

Related to PRs #61 & #62

cc @jshcrowthe

);
} else {
// Exact match on each key.
return this.callbacks_.every(<any>function (cb, eventType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jshcrowthe is the SDK using some library that adds the every method to Object.prototype? Otherwise, this looks like a bug to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it is indeed a bug, we could add this function to src/utils/obj.ts:

export const every = function(obj, fn) {
  for (let key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      if (!fn(key, obj[key])) {
        return false;
      }
    }
  }
  return true;
};

and then replace this block of code with:

return every(this.callbacks_, (eventType, cb) => other.callbacks_[eventType] === cb);

Let me know! :)

Copy link
Contributor

@jshcrowthe jshcrowthe Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reviewing this at 3 AM but triggering this code proves you right. If we can add the helper fxn and update that block that'd be fantastic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Josh, go get some sleep!

I'll update this as soon as I get home :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@jsayol jsayol force-pushed the db-classes branch 2 times, most recently from ff6727c to 1e51f99 Compare June 16, 2017 12:40
@googlebot
Copy link

CLAs look good, thanks!

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@jsayol
Copy link
Contributor Author

jsayol commented Jun 16, 2017

I think I just offended the Git gods somehow... let me try to fix this.

Edit: phew, we're back on track.

@googlebot
Copy link

CLAs look good, thanks!

@jsayol jsayol force-pushed the db-classes branch 2 times, most recently from 327ee91 to 9afcadf Compare June 16, 2017 18:01
@jsayol
Copy link
Contributor Author

jsayol commented Jun 16, 2017

That's all the classes done so feel free to review the changes.

@jshcrowthe
Copy link
Contributor

Perfect. Thanks a ton @jsayol! With how large the database-ts branch is becoming, I am probably going to break things up a little. I'll get back to you with where this PR should be pointed.

@jshcrowthe
Copy link
Contributor

jshcrowthe commented Jun 16, 2017

@jsayol If you can please point this PR to https://github.com/firebase/firebase-js-sdk/tree/ts-database/add-new-impl (which will get incrementally merged in #62) then we can get this tested and merged.

@jsayol
Copy link
Contributor Author

jsayol commented Jun 16, 2017

Sure. Should I tag it as [Part 3/3]?

@jsayol jsayol changed the title feat(database): Convert several ES5 classes to TS classes refactor(database): classes for typescript database implementation [Part 3/3] Jun 16, 2017
@jsayol jsayol changed the base branch from database-ts to ts-database/add-new-impl June 16, 2017 19:46
@jsayol
Copy link
Contributor Author

jsayol commented Jun 16, 2017

Yeah, Github didn't like it when I changed the base branch. I might have to rebase, one sec.

Edit: done.

@jshcrowthe
Copy link
Contributor

jshcrowthe commented Jun 16, 2017

I actually have another part 3 of my own, this will be a piece of part 2 😄

@jshcrowthe jshcrowthe changed the title refactor(database): classes for typescript database implementation [Part 3/3] refactor(database): classes for typescript database implementation Jun 16, 2017
@jsayol
Copy link
Contributor Author

jsayol commented Jun 16, 2017

Ah! Sorry, jumped the gun there :P

@jshcrowthe jshcrowthe self-assigned this Jun 16, 2017
Copy link
Contributor

@jshcrowthe jshcrowthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First look at this is really good. I have been left some comments on the Error/Closure comment style that if you could address would be awesome!

Thank you much for the typescript refactoring! It looks nice so far.

* @private
* @const
* @type {!fb.core.snap.Node}
* @param {!fb.core.snap.Node} node_ A SnapshotNode to wrap.
Copy link
Contributor

@jshcrowthe jshcrowthe Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor the fb.*.*.* comments? These all have clear analogs in the classes that we reference.

* @return {!firebase.Promise}
*/
cancel(opt_onComplete) {
validateArgCount('firebase.database.onDisconnect().cancel', 0, 1, arguments.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change these validate identifiers to

validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);

I feel like with this being a class we should validate in the same way

Same principle for all of these below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. This originally said Firebase.onDisconnect().cancel so I changed the Firebase part to firebase.database. I've done the same in some other classes too, so just to be clear: in general should I remove the Firebase/firebase.database prefix and simply use the ClassName.methodName format?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, with these classes exposed, directly referencing the classes should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed both comments, plus a few other things I've found along the way.

I pushed these changes on a separate commit to make them easier to review, let me know if you want me to squash them before merging.

// no-op since we just always call getToken.
}

/** @inheritDoc */
onDisconnectPut(pathString, data, opt_onComplete) { }
onDisconnectPut(pathString: string, data: any, onComplete?: (a: string, b: string) => any) { }
Copy link
Contributor

@jshcrowthe jshcrowthe Jun 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like converting ServerActions to an abstract base class with default implementations for these methods would probably remove the need for the empty methods. I don't think it should block this PR but something to do in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's a good point. I'll create a new PR against ts-database/add-new-impl with that change, thanks!

@jshcrowthe
Copy link
Contributor

I've tested this and things are looking fantastic. I'm in the process of fixing node support and then importing tests so hopefully we can get all of these changes into master soon!

@jshcrowthe jshcrowthe merged commit 7efa1b0 into firebase:ts-database/add-new-impl Jun 17, 2017
@jsayol jsayol deleted the db-classes branch June 17, 2017 08:26
jshcrowthe pushed a commit that referenced this pull request Jun 20, 2017
* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements
jshcrowthe pushed a commit that referenced this pull request Jun 20, 2017
* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements
jshcrowthe added a commit that referenced this pull request Jun 28, 2017
…#62)

* refactor(database): add typescript implementation

* refactor(database): update build process to include database.ts

All integration tests pass at this point

* refactor(*): refactor environment builds to be based on separate .ts files

* WIP: patch database code in nodeJS

* refactor(database): classes for typescript database implementation (#55)

* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements

* fix(database): Add missing "typeof" (#74)

https://github.com/firebase/firebase-js-sdk/blob/fd0728138d88c454f8e38a78f35d831d6365070c/src/database/js-client/core/Repo.js#L86

* WIP: fixes from @schmidt-sebastian's review

* WIP: fix: TS Build error

* fix(database): fix issue with missing repo method

* WIP: review adjustments #1

* WIP: review comments #2
jsayol added a commit to jsayol/firebase-js-sdk that referenced this pull request Jun 29, 2017
…irebase#55)

* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements
jshcrowthe added a commit that referenced this pull request Jul 6, 2017
* refactor(database): add typescript implementation

* refactor(database): update build process to include database.ts

All integration tests pass at this point

* refactor(*): refactor environment builds to be based on separate .ts files

* WIP: patch database code in nodeJS

* refactor(database): classes for typescript database implementation (#55)

* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements

* WIP: add the /tests/config dir to the .gitignore

* WIP: add test harness

* WIP: add query tests

There are some tests that have weird timing issues, and because of the polling nature of the
original implementation, we never caught the issue. These should be resolved when able

* WIP: add database.test.ts

* WIP: add node.test.ts

* WIP: add sortedmap.test.ts

* WIP: add datasnapshot.test.ts

* WIP: add sparsesnapshottree.test.ts

* refactor(database): refactor query.test.ts to better preserve original test meaning

* WIP: add crawler_support.test.ts

* WIP: refactor EventAccumulator.ts for data.test.ts

* WIP: fix issue with query.test.ts

* WIP: add connection.test.ts

* WIP: add info.test.ts

* WIP: add order_by.test.ts

I only migrated some of these tests as there was a dependency on the server for several tests

* WIP: fix several code signature problems, add test files

* WIP: add transaction.test.ts

* WIP: working on the broken npm test command

* WIP: working on fixes

* WIP: remove logging

* WIP: fix node tests

* fix(*): fixing test files and CI integration

* WIP: tEMP: Allow branch builds

* WIP: escape string

* refactor(CI): use ChromeHeadless launcher

* WIP: fixes from review.

* WIP: skip flakey test

* WIP: remove unneeded debugger statement

* WIP: fixing nits
jshcrowthe added a commit that referenced this pull request Jul 6, 2017
* refactor(database): remove old database implementation [Part 1/3] (#61)

* refactor(database): remove old database implementation

This is part #1 of 4 PR's to migrate database

* refactor(database): remove database build processes

* refactor(database): Add typescript database implementation [Part 2/3] (#62)

* refactor(database): add typescript implementation

* refactor(database): update build process to include database.ts

All integration tests pass at this point

* refactor(*): refactor environment builds to be based on separate .ts files

* WIP: patch database code in nodeJS

* refactor(database): classes for typescript database implementation (#55)

* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements

* fix(database): Add missing "typeof" (#74)

https://github.com/firebase/firebase-js-sdk/blob/fd0728138d88c454f8e38a78f35d831d6365070c/src/database/js-client/core/Repo.js#L86

* WIP: fixes from @schmidt-sebastian's review

* WIP: fix: TS Build error

* fix(database): fix issue with missing repo method

* WIP: review adjustments #1

* WIP: review comments #2

* WIP: refactor(database): Add migrated test harness [Part 3/3] (#71)

* refactor(database): add typescript implementation

* refactor(database): update build process to include database.ts

All integration tests pass at this point

* refactor(*): refactor environment builds to be based on separate .ts files

* WIP: patch database code in nodeJS

* refactor(database): classes for typescript database implementation (#55)

* refactor(database): classes for typescript database implementation

* refactor(database): requested changes & other improvements

* WIP: add the /tests/config dir to the .gitignore

* WIP: add test harness

* WIP: add query tests

There are some tests that have weird timing issues, and because of the polling nature of the
original implementation, we never caught the issue. These should be resolved when able

* WIP: add database.test.ts

* WIP: add node.test.ts

* WIP: add sortedmap.test.ts

* WIP: add datasnapshot.test.ts

* WIP: add sparsesnapshottree.test.ts

* refactor(database): refactor query.test.ts to better preserve original test meaning

* WIP: add crawler_support.test.ts

* WIP: refactor EventAccumulator.ts for data.test.ts

* WIP: fix issue with query.test.ts

* WIP: add connection.test.ts

* WIP: add info.test.ts

* WIP: add order_by.test.ts

I only migrated some of these tests as there was a dependency on the server for several tests

* WIP: fix several code signature problems, add test files

* WIP: add transaction.test.ts

* WIP: working on the broken npm test command

* WIP: working on fixes

* WIP: remove logging

* WIP: fix node tests

* fix(*): fixing test files and CI integration

* WIP: tEMP: Allow branch builds

* WIP: escape string

* refactor(CI): use ChromeHeadless launcher

* WIP: fixes from review.

* WIP: skip flakey test

* WIP: remove unneeded debugger statement

* WIP: fixing nits

* Prevent using uninitialized array in EventEmitter (#85)

* perf(*): fixing build size output issues

* chore(*): remove unneeded build deps
@firebase firebase locked and limited conversation to collaborators Oct 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants