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

Observe a resource and all params variant #25

Closed
lifeisfoo opened this issue Dec 18, 2015 · 1 comment
Closed

Observe a resource and all params variant #25

lifeisfoo opened this issue Dec 18, 2015 · 1 comment

Comments

@lifeisfoo
Copy link
Contributor

I've a tableview for a list of objects that are returned from an url like /resource.
In the same view there is a filter to get only a part of these object using a url like /resource?filterByDate=2015-12-18.

In the Siesta withParam documentation there is a statement about the uniqueness of the Resource given from its full URL.

In this way I need to add an observer (the view, self), to a new Resource, every time the user select a different filter for the list.

Is there a way to observe a resource and, automatically, all its "withParams" variants? Something like myResource.observeAllParams(self).

I've seen the source but I didn't find an easy way to implement this.

@pcantrell
Copy link
Member

If two things are the same resource, then they must have the same data. Thus you definitely want /resource and /resource?filterByDate=2015-12-18 to be different resources: “all the things” and “things from Dec 18” are different pieces of information. It’s best to think of them as entirely separate resources.

In this way I need to add an observer (the view, self), to a new Resource, every time the user select a different filter for the list.

Yes, that’s exactly right.

In fact, it’s best not just to add the observers to the new resource, but to remove the old one as well. Think of your table view as always showing some particular resource, and when you change filters, you change which resource it’s showing: “Now show all the things!” “Now show things from Dec 18!”

The idiom that keeps this clean is to create a “currently displayed resource” property with a setter that un-observers the old resources and starts observing the new one. Take a look at this code from the example project, which shows how to integrate this behavior with a table view:

https://github.com/bustoutsolutions/siesta/blob/master/Examples/GithubBrowser/Source/UI/RepositoryListViewController.swift#L14-L22

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