Closed guyjacks closed 7 years ago
I see ๐ค, donโt worry ๐, Iโll try to fix that for you as soon as possible. The $.live()
function will always have some bugs because Iโm trying to implement non-standards functions (in this case, Object.prototype.watch()
). Iโm nearly sure that the problem comes from the function itself.
In the next week, Iโll try to fix every function to deliver the v1.0.0
of DisplayJS as soon as possible.
Thank you ๐ for submitting this issue ๐.
Just to make sure, why are you using self
in the ห$.live()ห function? I think ๐ค there is an issue here, because the หselfห object is not ment to be use here ๐.
For the moment, you can use:
var cart = {
amount: 0.0,
charge: 0.0
};
var $djs = new DisplayJS(cart);
$djs.var();
$djs.target(function () {
var charge = calcCharge(parseInt(cart.amount));
cart["charge"] = charge;
$djs.var()
});
function calcCharge(goal) {
var stripeFixed = 0.3;
var stripePercent = 0.029;
var numerator = goal + stripeFixed;
var denominator = 1.0 - stripePercent;
var charge = numerator / denominator;
return charge;
}
I didn't mean to leave the "self" in there. I was trying something else and forgot to remove it. It's gone now.
@guyjacks Also, the $.live()
is not a function that should be used often, especially in small projects. DisplayJS have a lot of way to dynamically update values. So, I simply used a callback in the $.target()
function to update everything ๐
I just got it working with the code you shared above. Thank you.
The problem was that you triggered 2 things in the exact moment (which is technically impossible in JavaScript, but because I'm dealing with low-level APIs, there is bugs), but because JavaScript is a working on single core, your browser that simply doesn't want to crash skip this step ๐
https://codepen.io/guyjacks/pen/eRwadE
This is probably more of a javascript issue than an issue with DJS, but I can't figure out how to prevent an infinite loop from occurring when I update the variable that I'm watching.
I don't see the difference between my example and the dog example in the docs.
I love this little framework... Cheers!