-
Notifications
You must be signed in to change notification settings - Fork 869
Conversation
I'm not opposed to adding it back but then we need to make it a documented public API, or we'll likely break it again. However currently schemas don't have any "introspection" public API at all. Now that we're at it, do you think it's worth adding any other methods to the schemas for third-party libraries? |
I'm also using the undocumented I can add documentation for |
I've added docs for those two methods and a few more lines of tests. I'm open to adding more methods if anyone has further needs, but these feel like enough to me for |
Do you have any problems with the case where |
Out in 2.0.0. |
@paularmstrong This method seems to have disappeared again in v3.x - is there a reason for that and can we get it back? |
@atrefz I don't understand the use-case in continuing to support this as a public method. Normalizr 3.0 includes breaking changes that would make this function not very usable outside of the normalization process. The equivalent of |
This is useful for libraries that wrap around normalizr, and want to offer abstractions. In my specific use case: I am maintaining a generic-api package that lets you define schemas with normalizr among other things. The packages offers one specific abstraction that allows you to just query Now, I understand that |
@atrefz if you're writing an abstraction on top of normalizr, why don't you do just that? import { schema } from 'normalizr';
export class Entity extends schema.Entity {
getIdAttribute() {
return this._getId;
}
} You may have to change what's getting returned from time to time, but I don't think I feel comfortable supporting |
First of all I need to clarify, while this project is abstracting some things that have to do with normalizr it still expecting normalizr schemas as its input - the generic-api is not itself defining the schemas, so we can't extend the class like you suggest(without a lot of wrapping and unwrapping at least). More importantly however: We don't need the id value, we already got that under the name We want to transform like this: let data = { id: 'foo' }
let correctedData = { [schema.getIdAttribute()]: data.id } There really is no reason to prevent users from accessing this key and it is clearly useful to multiple open source projects. The solution I was about to propose is incidentally exactly how this was implemented before: Simply saving This seems like no effort whatsoever and I don't see any support effort either - you just pass back what you got as an option. That those 2 things are in direct correlation is obvious to anybody using this method IMHO. If that still makes you uncomfortable you could make it a private method |
Ah, I understand now. Thanks for clarifying (and sorry I'm a little thick-headed 😉). I'd accept a PR that implements |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This adds back the
getIdAttribute()
method that existed inv1.0.0
.This is helpful for me when using with a library like
redux-crud
where it also needs theidAttribute
passed in as an option. With this change I can create my schema as usual, and then read the idAttribute and pass it directly to theredux-crud
reducer for each entity.