Skip to content

remove after dependency #79

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

Merged
merged 5 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

var Emitter = require('component-emitter');
var after = require('@ndhoule/after');
var each = require('@ndhoule/each');
var events = require('analytics-events');
var every = require('@ndhoule/every');
Expand Down Expand Up @@ -334,8 +333,16 @@ exports._wrapInitialize = function() {
*/

exports._wrapPage = function() {
// Noop the first page call if integration assumes pageview
if (this._assumesPageview) return this.page = after(2, this.page);
var page = this.page;
this.page = function() {
if (this._assumesPageview) {
if (this._initialPageSkipped) return page.apply(this, arguments);

return this._initialPageSkipped = true;
Copy link

Choose a reason for hiding this comment

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

similar to my question #123

what do we expect this method to return ? It's a bit confusing reading that line, because it appears that we're returning a boolean, but that doesn't appear to be the intention. If the method return null, it might be clearer if we just used two lines, one to set the var, the other to explicitly return.

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!

}

return page.apply(this, arguments);
Copy link
Contributor

@fathyb fathyb Nov 19, 2019

Choose a reason for hiding this comment

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

Is there a need to store initialPageSkipped on the instance? It could be simplified to:

  var page = this.page;
  var initialPageSkipped = false;
  this.page = function() {
    if (this._assumesPageview && !initialPageSkipped) {
      return initialPageSkipped = true;
    }

    return page.apply(this, arguments);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. fixed!

};
};

/**
Expand Down
1 change: 1 addition & 0 deletions lib/statics.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports.global = function(key) {

exports.assumesPageview = function() {
this.prototype._assumesPageview = true;
this.prototype._initialPageSkipped = false;
return this;
};

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
"homepage": "https://github.com/segmentio/analytics.js-integration#readme",
"dependencies": {
"@ndhoule/after": "^1.0.0",
"@ndhoule/clone": "^1.0.0",
"@ndhoule/defaults": "^2.0.1",
"@ndhoule/each": "^2.0.1",
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
# yarn lockfile v1


"@ndhoule/after@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@ndhoule/after/-/after-1.0.0.tgz#e6d86d121448247ac742ff3a61c63fae83ee1191"
dependencies:
"@ndhoule/arity" "^2.0.0"

"@ndhoule/arity@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@ndhoule/arity/-/arity-2.0.0.tgz#26bfa0b9755ced9aea819d4e6e7a93db27a5b658"

"@ndhoule/clone@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@ndhoule/clone/-/clone-1.0.0.tgz#0f68394a95008cf360370e101924564a70927afc"
Expand Down