adlnet / xAPIWrapper

Wrapper to simplify communication to an LRS
https://adlnet.gov/projects/xapi/
Apache License 2.0
214 stars 114 forks source link

addGroupingActivity() calls always initiate an empty array #160

Closed brian-learningpool closed 4 years ago

brian-learningpool commented 4 years ago

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 https://github.com/adlnet/xAPIWrapper/blob/c7bc09f28a6500924e2f4cef8e4d992c03cdd98b/src/xapistatement.js#L12.

Something like

if (!Array.isArray(obj[part])) {
  obj[part] = [];
}
vbhayden commented 4 years ago

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

vbhayden commented 4 years ago

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.