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

Added "_path" and "_name" properties to ObjPathProxy #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

tran-simon
Copy link

This adds the ability to get the path of the ObjPathProxy object without having to use the "getPath" function every time.

Exemple:

interface IExample extends ObjPath {
  one: number;
  two: string;
  nested: IExample;
  collection: IExample[];
}
const p = createProxy<IExample>();
console.log(p.one._path); //  'one'
console.log(p.nested.collection[2].one._path); //'nested/collection/2/one'
console.log(p.one._name); //  'one'
console.log(p.nested.collection[2].one._name); //'one'

@@ -1,4 +1,10 @@
export interface ObjPath {
_pathString: string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using Symbols instead of underscored prop names. This would also make them private.

return proxy as any as ObjPathProxy<T, T>;
}

export function getPath<TRoot, T>(proxy: ObjProxyArg<TRoot, T>): PropertyKey[] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing those functions makes this lib incompatible with previous version. That would be a breaking change.
If the reason of adding the _path prop was to cache path instead of computing it every time, I'd suggest returning the _path value in the getPath function

Copy link
Owner

@Taras-Tymchiy Taras-Tymchiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Simon!
Thank you for spending your time on making this PR. I appreciate it!
I left a few suggestions in the inline comments.

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

Successfully merging this pull request may close these issues.

None yet

2 participants