Skip to content

Commit

Permalink
fix(hierarchy): collect events from static and intstance members
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 8, 2016
1 parent 73ba79b commit 6f98562
Show file tree
Hide file tree
Showing 58 changed files with 447 additions and 257 deletions.
30 changes: 24 additions & 6 deletions lib/hierarchy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var _ = require('lodash');
var hasOwnProperty = Object.prototype.hasOwnProperty;

/**
Expand Down Expand Up @@ -119,16 +120,24 @@ module.exports = function (comments) {
comment.members[scope] = node.members[scope];
}

var events = comment.members.events || [];
var groups = [];

if (comment.members.instance.length) {
comment.members.events = comment.members.instance.filter(function (member) {
return member.kind === 'event';
});
groups = _.groupBy(comment.members.instance, isEvent);

comment.members.instance = comment.members.instance.filter(function (member) {
return member.kind !== 'event';
});
events = events.concat(groups[true] || []);
comment.members.instance = groups[false] || [];
}

if (comment.members.static.length) {
groups = _.groupBy(comment.members.static, isEvent);

events = events.concat(groups[true] || []);
comment.members.static = groups[false] || [];
}

comment.members.events = events;

comment.path = path.map(pick).concat(pick(comment));

Expand Down Expand Up @@ -168,3 +177,12 @@ module.exports = function (comments) {

return toComments(root.members.static);
};

/**
* Check if a given member object is of kind `event`.
* @param {Object} member - The member to check.
* @returns {boolean} `true` if it is of kind `event`, otherwise false.
*/
function isEvent(member) {
return member.kind === 'event';
}
9 changes: 6 additions & 3 deletions test/fixture/_external-deps-included.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -275,7 +276,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -436,7 +438,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
6 changes: 4 additions & 2 deletions test/fixture/_multi-file-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -393,7 +394,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/boolean-literal-type.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
],
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
6 changes: 4 additions & 2 deletions test/fixture/class.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@
"scope": "instance",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -551,7 +552,8 @@
"scope": "instance",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"name": "document-exported-export-default-object.input",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -66,7 +67,8 @@
"name": "x",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"name": "document-exported-export-default-value.input",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
Loading

0 comments on commit 6f98562

Please sign in to comment.