Created
October 11, 2018 14:52
-
-
Save joshhunt/6bb0744f4f09b03b11b2e0b741349b62 to your computer and use it in GitHub Desktop.
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 makeMessages = (src = {}, path = []) => | |
new Proxy(src, { | |
get(target, name) { | |
const newPath = [...path, name]; | |
// For _any_ key on messages, return a function that returns the string-path to that key. | |
// Also, wrap that function in this proxy to do the same for any key on the function | |
return makeMessages(() => newPath.join('.'), newPath); | |
} | |
}); | |
const messages = makeMessages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment