Famous/famous-angular

$famous.find doesn't always work

Closed this issue · 3 comments

If a classname is generated on a local scope and not a static string, the $famous Provider will sometimes fail to find a RenderNode that references the className. This prevents the use of the 'deploy' event on RenderNodes as you cannot call $famous.find(".dynamicClass")[0].renderNode.on("deploy"). I have created a pull request with a possible fix for this problem.

Hey -

When are you executing your find? "As in normal Angular, this DOM look-up should be performed in the postLink function of a directive." FA Docs. I would expect you to get your desired result if you placed your $famous.find in a timeout. I do not recommend that as your final solution but just a test to ensure that it is a timing issue not a $famous.find issue. I literally encountered this a few minutes ago.

Let me know when that PR is ready and Ill take another look at it. I spoke with Zack and he confirmed that it does seem like a useful feature but it would need unit test support.

Thanks,

Jordan

We usually reserve calls to $famous.find in a post link function of a directive, but even then sometimes it takes a $timeout or even long polling (the second or third poll the provider usually resolves to the element). Sometimes we need to both wait for a model to load async while also waiting for famo.us/angular to compile. It just seems like the approach I submitted is more straightforward at times or a decent option at least. Implementing $famous.find in the post link doesn't always work and returns undefined because the DOM element simply isn't compiled or possibly hasn't been registered with the provider yet? In theory, it sounds like the element should be there in the post link step. That would be logical but doesn't always happen in practice.

I merged you PR. Please close this issue if it is now working.

Thanks,

Jordan