-
Notifications
You must be signed in to change notification settings - Fork 392
Cleaned up auth user types for easier debugging #1
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
* | ||
* For example, this can be used to map underscore_cased properties to camelCase. | ||
* | ||
* @param {obj} Object The object whose properties to rename. | ||
* @param {keyMap} Object The mapping from old to new property names. | ||
* @param {Object} obj The object whose properties to rename. | ||
* @param {Object} keyMap The mapping from old to new property names. | ||
*/ | ||
export function renameProperties(obj: Object, keyMap: { [key: string]: string }): void { | ||
Object.keys(keyMap).forEach((oldKey) => { | ||
|
@@ -16,3 +16,23 @@ export function renameProperties(obj: Object, keyMap: { [key: string]: string }) | |
} | ||
}); | ||
} | ||
|
||
/** | ||
* Defines a new property directly on an object, or modifies an existing property on an object, and | ||
* returns the object. | ||
* | ||
* @param {Object} obj The object on which to define the property. | ||
* @param {string} prop The name of the property to be defined or modified. | ||
* @param {any} value The value associated with the property. | ||
* | ||
* @return {Object} The object that was passed to the function. | ||
*/ | ||
export function addGetter(obj: Object, prop: string, value: any): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be renamed to something like addReadonlyGetter or something of the like since a getter does not necessarily imply the property does not have a setter? Also would be helpful to a test for this, where you add a readonly property on an object, try to change its value and then check the old value is still there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Object.defineProperty(obj, prop, { | ||
value, | ||
// Make this property read-only. | ||
writable: false, | ||
// Include this property during enumeration of obj's properties. | ||
enumerable: true, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
readonly
here is a compilation time check only. I think it's useful to have to make sure we don't accidentally set the property in our own codebase, but it does not enforce read-only behavior for end-users. That is why I needed to explicitly useObject.defineProperty()
below to enforce the read-only behavior.