derbyjs / racer

Realtime model synchronization engine for Node.js
1.18k stars 116 forks source link

Add alternative signatures for Model#start and Model#on that don't use var-args #263

Closed ericyhwang closed 5 years ago

ericyhwang commented 5 years ago

The var-args in the middle of parameter lists for Model#start and Model#on make it difficult to write TypeScript type definitions for them.

These backwards-compatible changes add alternative signatures that don't use var-args.

1) Model#start now supports a new array format for input paths:

  model.start(outPath, inPath1, inPath2, ..., fn);  // Old
  model.start(outPath, [inPath1, inPath2, ...], fn); // New

2) Model#on has a new {useEventObjects: boolean} option. If true, it calls the listener with an Event object and the wildcard-captured segments as an array:

  // Old
  model.on('change', 'foo.**', (captures..., value, previous, passed) => {
  });
  // New
  model.on('change', 'foo.**', {useEventObjects: true}, (changeEvent, captures) => {
    const {type, value, previous, passed} = changeEvent;
  });

Once this is published, I'll update derby-site with documentation on the new signatures and event objects.