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

Cleanup mojito #37

Merged
merged 8 commits into from
Dec 20, 2019
Merged

Cleanup mojito #37

merged 8 commits into from
Dec 20, 2019

Conversation

dapperdrop
Copy link
Member

Ref: #35

  • Removed unused code: veil, etc
  • Tidy up + make commenting consistent
  • Added TODOs: optimise and/or refactor certain blocks, please take a look at these especially @allmywant

Copy link
Member

@kingo55 kingo55 left a comment

Choose a reason for hiding this comment

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

Everything is checking out from my end.

I added some new unit tests on a local branch I'm working on and the cleaned up lib is passing with flying colours.

The other comments about refactoring, I have added new issues around those so we can keep more PRs a bit tighter.

lib/mojito.js Outdated
if (inTest)
{
this.setInTest(1);

// TODO: optimise logic?
Copy link
Member

Choose a reason for hiding this comment

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

I think something like this could work, but @allmywant would probably know a better way to handle this.

                    var chosenRecipe = this.getRecipe() || this.chooseRecipe();
                    this.setRecipe(chosenRecipe);

                    // Exclude users from test if their chosen recipe no longer exists
                    var chosenRecipeObject = this.options.recipes[chosenRecipe];
                    if (!chosenRecipeObject)
                    {
                        this.setInTest(0);
                        return success;
                    }
                    else this.setInTest(1);

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed: 95e244c

Copy link
Member Author

Choose a reason for hiding this comment

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

Ref: f20f1f3

I moved this.setInTest(1) back to the start of this block as it was breaking a unit test.

setInTest(1) does some cookie testing which this.getRecipe() relies on. This caused a chicken and egg bug.

Copy link
Member

Choose a reason for hiding this comment

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

@allmywant - should address this when refactoring get/set recipe/test functions in #40

lib/mojito.js Outdated
Comment on lines 258 to 283
{
this.chosenRecipe = recipe;
var success = false;
// assign an empty function if 'onChosen' is not defined

// TODO: refactor following block, see comment below for recipe.js(this)
// Assign an empty function if 'onChosen' is not defined
if (!recipe.js)
{
recipe.js = function () {};
}

// Check if unveil is needed
if (this.needUnveil())
{
// hide or shift body out of screen
this.hideBodyElement(recipe);
}

// for Unveil cases, timeout reached before onChosen get called.
if (this.options.executed)
{
return success;
}

try
{
// test level css
// Inject test level css
if (this.options.css)
{
this.injectCSS(this.options.css);
}
// recipe level css
// Inject recipe level css
if (recipe.css)
{
this.injectCSS(recipe.css);
}

// TODO: refactor? if(receipe.js) recipe.js(this);
recipe.js(this);
Copy link
Member

Choose a reason for hiding this comment

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

We don't strictly need to add an empty function do we?:

                this.chosenRecipe = recipe;
                var success = false;

                try
                {
                    // Test level css
                    if (this.options.css)
                    {
                        this.injectCSS(this.options.css);
                    }
                    // Recipe level css
                    if (recipe.css)
                    {
                        this.injectCSS(recipe.css);
                    }
                    // Recipe level js
                    if (recipe.js) 
                    {
                        recipe.js(this);
                    }

                    success = true;
                    this.log("Test Object [" + this.options.name + "][" + this.options.id + "] recipe onChosen [" + recipe.name + "][" + recipe.id + "] run.");
                }

Copy link
Member Author

Choose a reason for hiding this comment

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

@allmywant - would you mind commenting on this? If we don't strictly need:

if (!recipe.js)
                {
                    recipe.js = function () {};
                }

Then I will remove it in another commit. This should be the last item to resolve for this PR, unless you guys see something else should be addressed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed: f20f1f3

@kingo55 kingo55 added the enhancement New feature or request label Dec 19, 2019
@dapperdrop
Copy link
Member Author

Maybe make this comment a bit clearer to reflect the logic:

"Assign recipes to users in test, else exclude them by test's sample rate"

Done: 062d8e3

@allmywant
Copy link
Member

@dapperdrop

if (!recipe.js)
{
recipe.js = function () {};
}
Then I will remove it in another commit. This should be the last item to resolve for this PR, unless you guys see something else should be addressed.


Yes, we don't need it.
I also left some comments in this pr but it seems not visible to you guys. e.g. :

Move var seededRNGSeed = (new Date()).getTime(); here means the initial seed will be created every time we call getSeededRNGRandom function, seems not correct. This the only question I'd like to confirm before approving.

Please let me know if you have seen it, maybe I did something wrong when I submit review comments.

@dapperdrop
Copy link
Member Author

Thanks @allmywant - I didn't see your other comments, thanks for letting us know.

Move var seededRNGSeed = (new Date()).getTime(); here means the initial seed will be created every time we call getSeededRNGRandom function, seems not correct. This the only question I'd like to confirm before approving.

Good spot there. I'm not sure either, @kingo55 do you know?

@kingo55
Copy link
Member

kingo55 commented Dec 20, 2019

@allmywant - did you "Submit" the code review? I had that issue the other day where I thought I added questions to a PR, but they weren't visible until I hit the "Submit review" section. Github code review submission is not so clear IMO.

Screen Shot 2019-12-20 at 10 59 37

Copy link
Member

@allmywant allmywant left a comment

Choose a reason for hiding this comment

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

@kingo55
Maybe I just left comments but didn't click the "Submit review" button.

lib/mojito.js Outdated
* @private
*/
getSeededRNGRandom: function ()
{
// initial seed
var seededRNGSeed = (new Date()).getTime();
Copy link
Member

Choose a reason for hiding this comment

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

@dapperdrop
Move var seededRNGSeed = (new Date()).getTime(); here means the initial seed will be created every time we call getSeededRNGRandom function, seems not correct.

@kingo55 What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@dapperdrop @kingo55
What do you guys think on this one? This the only question I'd like to confirm before approving.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll move this back

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed: f20f1f3

@@ -220,13 +197,12 @@ Mojito = (function ()
}
}

this.options.newToThisTest = newToThisTest;
Copy link
Member

Choose a reason for hiding this comment

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

@dapperdrop
If this line is removed, we are not to able access newToThisTest in tracking code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this was only used as part of veil functionality, so it should be safe to remove if we removed veil.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @dapperdrop , that make sense.

Copy link
Member

Choose a reason for hiding this comment

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

I was leaning towards not including this because we can infer this from the existance of decisionIdx or seed/hash on the test object.

It looks clearer having a name newToTest on the test object though. So if users only want to fire the tracking once per test, that would save data.

Up to @dapperdrop whether we keep this or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've re-instated this in: f20f1f3

lib/mojito.js Outdated
if (recipe.css)
{
this.injectCSS(recipe.css);
}

// TODO: refactor? if(receipe.js) recipe.js(this);
Copy link
Member

Choose a reason for hiding this comment

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

Good point!

@kingo55
Copy link
Member

kingo55 commented Dec 20, 2019

Move var seededRNGSeed = (new Date()).getTime(); here means the initial seed will be created every time we call getSeededRNGRandom function, seems not correct. This the only question I'd like to confirm before approving.

Good spot there. I'm not sure either, @kingo55 do you know?

I'm not sure. Perhaps it's safer for us to move it back so we're not unintentionally changing the logic of this old function at all.

@dapperdrop dapperdrop merged commit 44932ec into mint-metrics:master Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants