Skip to content

Conversation

@dunksmith
Copy link

An attempt to resolve two issues:

@beezee
Copy link
Owner

beezee commented Sep 14, 2015

Seems simple enough and I appreciate the PR. 2 qs-

1- What is the advantage of requiring the content be specified on an attribute? Especially in your example it seems to duplicate and create unnecessary verbosity
2- Where does the timeout value come from? If there's a race condition here, is there an event we can explicitly listen for instead of an arbitrary wait?

@dunksmith
Copy link
Author

Hi - good questions, I'll try to explain my reasoning:

  1. A $watch without an expression gets fired with great frequency in AngularJS. This will cause massive performance problems for any non-trivial app, since dotdotdot could be re-initialized 100's of times a second (I've seen this first-hand).

So to your question - the crucial advantage is that we avoid the need for a global $watch. I'm pretty sure my code could be optimised to be more DRY by using ngBind or something, but as a first step I think it's a fair trade-off in simplicity vs performance.

  1. The timeout is basically there to wait for the DOM to render, so that dotdotdot will work. Currently the code (elegant as it is) works via brut-force: it keeps running all of the time, and at some point it happens to be the correct time.

There's a chance you could use a $watch expression instead on the element dimensions, and only initialize dotdotdot when they change. But in my experience (Ionic apps on Android/iOS and web) a delay of 400ms has worked well.

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

Successfully merging this pull request may close these issues.

2 participants