-
Notifications
You must be signed in to change notification settings - Fork 31
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
Cleanup mojito #37
Conversation
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.
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? |
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 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);
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.
Addressed: 95e244c
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.
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.
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.
@allmywant - should address this when refactoring get/set recipe/test functions in #40
lib/mojito.js
Outdated
{ | ||
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); |
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 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.");
}
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.
@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.
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.
Addressed: f20f1f3
Done: 062d8e3 |
Yes, we don't need it. 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. |
Thanks @allmywant - I didn't see your other comments, thanks for letting us know.
Good spot there. I'm not sure either, @kingo55 do you know? |
@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. |
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.
@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(); |
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.
@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?
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.
@dapperdrop @kingo55
What do you guys think on this one? This the only question I'd like to confirm before approving.
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'll move this back
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.
Addressed: f20f1f3
@@ -220,13 +197,12 @@ Mojito = (function () | |||
} | |||
} | |||
|
|||
this.options.newToThisTest = newToThisTest; |
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.
@dapperdrop
If this line is removed, we are not to able access newToThisTest
in tracking code.
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 think this was only used as part of veil functionality, so it should be safe to remove if we removed veil.
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.
Thanks @dapperdrop , that make sense.
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 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.
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'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); |
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.
Good point!
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. |
Ref: #35