Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$resource: enumerability of methods and properties, toJSON #14637

Open
jrvidal opened this issue May 19, 2016 · 1 comment
Open

$resource: enumerability of methods and properties, toJSON #14637

jrvidal opened this issue May 19, 2016 · 1 comment

Comments

@jrvidal
Copy link
Contributor

jrvidal commented May 19, 2016

Do you want to request a feature or report a bug?
Feature.

What is the current behavior?
If I want to apply some transformations to a Resource instance, I could encounter some nasty surprises:

Cat.get({id: catId}).$promise.then(cat => {
  this.catDetails = doSomethingWithPairs(_.pairs(cat));

  this.otherCatDetails = doSomethingElse(_.pairs(_.omit(cat, ["name", "$promise", "$resolved"])));
});

doSomethingWithPairs receives an array of pairs that contains ["$promise", /*...*/] and ["$resolved", /*...*/]. doSomethingElse contains entries for all instance methods (!) such as $get, $query, etc.

What is the expected behavior?

This is a weird interaction with Underscore defaults[1] that is not for Angular to fix. However, I do think that some things that could be improved:

  • Make $promise and $resolved non-enumerable properties of Resource instances.
  • Make all Resource instance methods non-enumerable (a la ES6 classes).
  • Document the behavior of Resource.prototype.toJSON method.

The latter is the workaround I have used to get a "normal" object from a Resource instance, although I would feel more confident if it were documented.

Other information (e.g. stacktraces, related issues, suggestions how to fix)
Related issues:


[1] Lodash only includes own, enumerable properties for omit.

@jrvidal jrvidal changed the title $resource: enumerable methods properties and toJSON $resource: enumerability of methods and properties, toJSON May 19, 2016
@gkalpak gkalpak added this to the Backlog milestone May 19, 2016
@gkalpak
Copy link
Member

gkalpak commented May 19, 2016

👍 for documenting Resource.prototype.toJSON. PRs welcome 😉

I would also consider making Angular-stuff non-enumerable in 1.6/1.7 (since it's a breaking change), as long as all supported browsers behave consistently.
If anyone wants to take a crack at it, please do !

petebacondarwin pushed a commit that referenced this issue Jun 9, 2016
Document the `toJSON` method of `Resource` instances as part of its public API.

See #14637
Closes #14725
petebacondarwin pushed a commit that referenced this issue Jun 9, 2016
Document the `toJSON` method of `Resource` instances as part of its public API.

See #14637
Closes #14725
@petebacondarwin petebacondarwin modified the milestones: Backlog, Ice Box Oct 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants