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

Async filter #2

Closed
rolaveric opened this issue Aug 27, 2015 · 1 comment
Closed

Async filter #2

rolaveric opened this issue Aug 27, 2015 · 1 comment

Comments

@rolaveric
Copy link
Owner

To take this example up to 11, going to need something equivalent to the 'async' pipe from the Angular 2 examples.

The common solution is to use a stateful filter:
http://stackoverflow.com/questions/19046641/asynchronously-initialize-angularjs-filter

@rolaveric
Copy link
Owner Author

Solved with 0d2bea0

Works by using the Model.getCache() method to get the data synchronously from the local cache. If said cache value is undefined, it makes a request with a safeApply($rootScope) on the observable, which then causes the filter to be rerun.
Rather than calling the filter async, I called it getValue (prefixed as rol_getValue) since it's specific to calling Model.getValue(), rather than being generic to all observables.

The problem with the generic observable solution is that each time the $digest loop runs, you have a new observable object to deal with. So you can't even create a mapping to substitute the correct value later.

Also created a pageRange (rol_pageRange) filter to help when dealing with a range of objects.
For example: You know there's a todos array in the JSON graph, but you can't retrieve the whole thing from FalcorJS. But you can retrieve it's length. And since length could be a huge value, you select a range of indexes from 0 to length - 1.

ng-repeat="index in 'todos.length' | rol_getValue:model | rol_pageRange:currentPage:pageSize"

Syntax could use some sugar, but it's sound.

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

1 participant