Created
May 17, 2017 22:26
-
-
Save iddan/2bcdf89ccd21436f1d8f7337fcc94c08 to your computer and use it in GitHub Desktop.
With Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WithPath = (target, path = []) => new Proxy(target, { | |
get(target, property, receiver) { | |
const value = target[property]; | |
const thisPath = [...path, property]; | |
return { | |
...(typeof value !== 'object' ? value : WithPath(value, thisPath)), | |
[WithPath.Path]: thisPath | |
}; | |
} | |
}); | |
WithPath.Path = Symbol('path'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment