question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lean mode should support "apos.on" for the "ready" event because everyone stubs their toe on it

See original GitHub issue

“apos.on” does not exist in lean mode. That makes sense. However everybody gets confused about how to attach their “enhance” or “ready” event handlers for non-widget code.

The right way to do that is:

if (!apos.on) {
  // safely after DOM is ready, like $(function() { ... })
  apos.utils.ready(invokeMyThing);
} else {
  // safely after DOM is ready AND when new widgets are ajaxed into the page while editing
  apos.on('enhance', invokeMyThing);
}

But this pattern is really tedious and everyone is having a tough time with it, which is breaking code on the front end.

So I propose it is worth a few bytes to support apos.on in the lean library, and to just have ready and enhance fire at apos.utils.ready time in lean mode, so code works either way. A few of the “if” statements above and you’ll actually have more code bloat than this simple pokeyoke to prevent bugs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
boutellcommented, Nov 25, 2019

My concern isn’t tedium, it’s the bug-prone nature of saying “you have to write this if statement to deal with the two cases, and you have to write it in many places.” That’s a clear tell that we should provide a simple way to work in both situations.

1reaction
stuartromanekcommented, Nov 25, 2019

If lean mode had more definition around it would be easier to make these decisions.

If lean mode just means no external dependencies then I don’t feel bad about filling in normal front-end apos functionality to keep code consistent and One Way.

The documentation for lean should be beefed up by adding a section around running non-widget code. Lean mode might also benefit from not just throwing everything into apos.utils, where we’re currently mixing jquery-like helpers with apostrophe specific ready code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LeanMode (Capsules) - Evlution Nutrition
LeanMode (Capsules) ... Metabolism support*; 5 modes of action; Appetite support* ... Definitely recommend added to your diet and exercise plan! Report as...
Read more >
Amazon.com: EVL LEANMODE Weight Loss Support
Buy EVL LEANMODE Weight Loss Support - Non-Stimulant Metabolism Support and Appetite Support for Men and Women - Lean Mode with Green Coffee...
Read more >
Leanmode Stimulant Free Fat Burner & Weight Loss ...
LeanMode Stimulant Free Weight Loss support. Metabolism Support; 5 Modes of Action; Appetite Support; Stimulant Free; Fat Burner; Gluten Free.
Read more >
The Book Thief - SharpSchool
—Of course, an introduction. A beginning. Where are my manners? I could introduce myself properly, but it's not really necessary. You will know ......
Read more >
LiveWell Employee Recipe Book 2016
Healthy Tip: Lean proteins such as fish, turkey, and chicken can help you build muscle, make your meal more filling, and provide many...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found