DavidWells / DavidWells/analytics
Update method injection with standard API
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 267
- PR merge metrics
- No merged PRs in 30d
Description
Custom methods have the analytics instance injected into them as last argument and into the this context if non-arrow function used. https://getanalytics.io/plugins/writing-plugins/#adding-custom-methods
TODO: Standardize this api to something like:
{
analytics: instance,
config, // > current plugin config,
}
https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/src/index.js#L981
function appendArguments(fn, extra = {}) {
return function () {
/* Get original args */
const args = Array.prototype.slice.call(arguments)
/* Create clone of args */
let newArgs = new Array(fn.length)
for (let i = 0; i < args.length; i++) {
newArgs[i] = args[i]
}
/* Append new arg to end */
newArgs[newArgs.length] = instance
// Set instance on extended methods
return fn.apply({ instance, ...extra }, newArgs)
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/analytics-core/src/index.js around line 981 and compare the current method injection with the custom-methods documentation. Trace how custom methods receive the analytics instance and plugin configuration; done means the injection follows one consistent object-based API and the documented behavior matches it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend-api-design
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100