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

infinite loop inside of live() #6

Closed
guyjacks opened this issue Jul 20, 2017 · 7 comments
Closed

infinite loop inside of live() #6

guyjacks opened this issue Jul 20, 2017 · 7 comments

Comments

@guyjacks
Copy link

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!

@arguiot
Copy link
Owner

arguiot commented Jul 20, 2017

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 😊.

@arguiot
Copy link
Owner

arguiot commented Jul 20, 2017

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 😊.

@arguiot
Copy link
Owner

arguiot commented Jul 20, 2017

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;
}

@guyjacks
Copy link
Author

I didn't mean to leave the "self" in there. I was trying something else and forgot to remove it. It's gone now.

@arguiot
Copy link
Owner

arguiot commented Jul 20, 2017

@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 😊

@guyjacks
Copy link
Author

I just got it working with the code you shared above. Thank you.

@arguiot
Copy link
Owner

arguiot commented Jul 20, 2017

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 😊

@arguiot arguiot closed this as completed Jul 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants