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

Is there a clean way I can know if given object is 'restangularized'? #1280

Open
Vladimir-Purple opened this issue Dec 13, 2015 · 6 comments

Comments

@Vladimir-Purple
Copy link

Hi.
Basically, I have situation where I have to know if object passed to the function is restangularized or not, it might be a collection or a single element.

I was thinking about two options.

First option, adding isRestangularized boolean property to each response via RestangularProvider.setResponseExtractor()
However, there is a problem with it, object can 'by pass' intercepter, for instance I can create restangularized element using Restangular.restangularizeElement() and it will not contain my isRestangularized property.

As second option, I can look for restangular properties that exist both in collections and elements such as addRestangularMethod by doing object.hasOwnProperty('addRestangularMethod') check.

Is there a better way? (using 1.4.0 version of Restangular)

@dreef3
Copy link
Contributor

dreef3 commented Dec 19, 2015

AFAIK there's a restangularized boolean property already. You can check for it.

@daviesgeek
Copy link
Collaborator

@Vladimir-Purple Does that work for you?

@nicolas-zozol
Copy link

It looks like this field does not exist anymore. I remember having use it last year. I test now on the function entity.addRestangularMethod ; Testing on a function avoid json pollution. I just hope this function will stay :)

@daviesgeek
Copy link
Collaborator

@nicolas-zozol This is still available as of the current version of Restangular. The preferred way to do it is actually element.isRestangularized(), which checks the underlying restangularized property, but that can be configured, so it's best to use isRestangularized()

@daviesgeek
Copy link
Collaborator

Can you verify for me that it's broken?

@nicolas-zozol
Copy link

Sorry I was wrong. Using Restangular 1.5.2, I have the field restangularized.

restangularized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants