adlnet/xAPIWrapper

addGroupingActivity() calls always initiate an empty array

Closed this issue · 2 comments

I noticed that the first statement was lost while trying to add two grouped items to my xAPI statement via addGroupingActivity() method. Is this by design or a bug?

I think maybe _getobj() requires a check before returning an empty array on

obj[part] = [];
.

Something like

if (!Array.isArray(obj[part])) {
  obj[part] = [];
}

Not sure, I'll take a look at this in a bit.

Yeah, this does look like a mistake. Just going into a console, you can see the behavior isn't correct:

statement.addGroupingActivity("A"); statement.addGroupingActivity("B");
console.log(statement.context.contextActivities.grouping.length)
>> 1

Go ahead and submit that change for a PR and I'll move it through.