-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
enable IDE auto-completion for the main classes #10618
base: develop
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -21,6 +21,10 @@ export const cardinal = { | |
northnorthwest: 337, nnw: 337 | ||
}; | ||
|
||
/** | ||
* @typedef {typeof prototype & iD.AbstractEntity} OsmNode | ||
* @returns {OsmNode} | ||
*/ | ||
export function osmNode() { | ||
if (!(this instanceof osmNode)) { | ||
return (new osmNode()).initialize(arguments); | ||
|
@@ -33,7 +37,7 @@ osmEntity.node = osmNode; | |
|
||
osmNode.prototype = Object.create(osmEntity.prototype); | ||
|
||
Object.assign(osmNode.prototype, { | ||
const prototype = { | ||
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. this is required so we can use |
||
type: 'node', | ||
loc: [9999, 9999], | ||
|
||
|
@@ -243,4 +247,5 @@ Object.assign(osmNode.prototype, { | |
coordinates: this.loc | ||
}; | ||
} | ||
}); | ||
}; | ||
Object.assign(osmNode.prototype, prototype); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
// Copies a variable number of methods from source to target. | ||
export function utilRebind(target, source) { | ||
var i = 1, n = arguments.length, method; | ||
while (++i < n) { | ||
target[method = arguments[i]] = d3_rebind(target, source, source[method]); | ||
/** | ||
* @template T | ||
* @template S | ||
* @template {keyof S} Args | ||
* @param {T} target | ||
* @param {S} source | ||
* @param {...Args} args | ||
* @returns {T & Pick<S, Args>} | ||
*/ | ||
export function utilRebind(target, source, ...args) { | ||
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. this had to be refactored to use spread arguments instead of the there's a new unit test to confirm that |
||
for (const method of args) { | ||
target[method] = d3_rebind(target, source, source[method]); | ||
} | ||
return target; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe('utilRebind', () => { | ||
it('copies methods from source to target', () => { | ||
const target = { original: 123 }; | ||
const source = new class { | ||
value = 456; | ||
method() { | ||
return this.value; | ||
} | ||
}; | ||
|
||
const copied = iD.utilRebind(target, source, 'method'); | ||
|
||
expect(copied).toStrictEqual({ | ||
original: 123, | ||
method: expect.any(Function) | ||
}); | ||
expect(copied.method()).toBe(456); | ||
}); | ||
}); |
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.
This works because JS autocompletion is powered by TypeScript, which is smart enough to infer the type of
context
when defined as an empty objectproof here
utilRebind can safely be moved to the
return
statement because this class does not usecontext.on
internally.