-
Notifications
You must be signed in to change notification settings - Fork 100
feat(typescript): class docs should link to inherited class docs #207
Conversation
c11fdaa
to
c0b1440
Compare
|
||
export class FirstParent extends LastParent { | ||
firstParentProp: string = 'Works'; | ||
_privateProperty: string = 'Private'; |
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.
you can also specify privacy by putting the private
keyword before the property
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.
We could. But I wanted this check to be private due to the leading underscore.
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.
Perhaps we should test both styles of private?
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.
Sounds good.
var inheritedMembers = resolveInheritedMembers(resolvedExport, typeChecker); | ||
|
||
for (var memberName in inheritedMembers) { | ||
if (memberName === 'T') continue; |
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 seems rather hard coded. I guess you are trying to spot generic methods?
What if someone used a different letter in their generic definition?
Or am I missing something?
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.
I didn't put much effort into that. This logic was copied from the for-loop below. Looks like Alex Eagle wrote it at this time.
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.
I see...
OK well if it worked before then I guess we should leave it the same for consistency for now.
Perhaps we could factor that bit into a shared function so that we only have to change it in one place if we decide it needs fixing in the future?
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 looks much better. I made a couple of inline comments.
I think it would be more effective if the inherited members each had a property that referenced the type from which they came. That way, one could group the inherited members by their heritage.
An alternative approach to this would be to identify the actual parent type (or more specifically the dgeni doc that represents the type) and just provide a property that references it. This way processors or templates could do the work of actually searching up the tree for the inherited members themselves - and you would get the ownership information I requested above for free.
e869492
to
fc85b36
Compare
* Introduces a new property on export docs that links to the class docs that are being inherited.
fc85b36
to
4c5b2cc
Compare
function resolveInheritedDocs(exportSymbol, exportDoc) { | ||
var inheritedSymbols = resolveInheritedSymbols(exportSymbol, typeChecker); | ||
var inheritedDocs = inheritedSymbols.map(function(symbol) { | ||
var relatedDoc = docs.find(function(doc) { return doc.exportSymbol === symbol; }); |
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 could be super slow, given that we are doing a search of o(n) on every single inheritance symbol.
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.
That's true. Should we use some faster search algorithms? Or do you have any better ideas? I thought about creating a Map of Symbols with their associated docs, but that would then fill-up memory..
OK, so this is really cool. I am worried about the performance time of doing all the searching.
This way we do not have to keep searching the docs for the appropriate symbol. What do you think? (sorry this is turning into a bit of an epic!) |
91ab3fa
to
99449c6
Compare
@petebacondarwin Made the requested changes. Please review again. |
**/ | ||
module.exports = function linkInheritedDocs(typescriptSymbolMap) { | ||
return { | ||
$runAfter: ['readTypeScriptModules'], |
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.
it is probably worth putting in a $runBefore
property too, since we can't guarantee that it will be run before other processors otherwise...
* To ensure that Dgeni properly recognizes classes from exports that will be parsed later, | ||
* the `FirstParent` class will be ordered after the `Child` class. | ||
**/ | ||
export class FirstParent extends LastParent { |
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.
is it worth putting in some implements
clauses to see what would happen?
@petebacondarwin Ping for review :) |
We got there! |
Introduce a new property `doc.inheritedDocs` on export docs that links to the class docs that this doc inherited from. This can be used in templates to show members for a class that were inherited from other classes. Closes #207
Uh oh!
There was an error while loading. Please reload this page.