Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LineUp column patcher extension #234

Merged
merged 2 commits into from
Oct 28, 2019

Conversation

puehringer
Copy link
Contributor

See #233 for a more information on the problem and why we need to solve it.

Usage
The column patcher is a simple function, included as extension point with the type tdpScoreColumnPatcher. The following example would modify an (already internally patched) NumberColumn score. The actual use case is to patch your own column, which is only accessible from within an app and has an known interface (with methods such as setCategories(...)).

  1. Add the extension to your phovea.ts:
  registry.push('tdpScoreColumnPatcher', 'another-number-column-patcher', () => System.import('./patcher/AnotherNumberColumnPatcher'), {
    factory: 'patchColumn'
  });
  1. As we have defined the factory: 'patchColumn', we have to create the file ./patcher/AnotherNumberColumnPatcher.ts with an exported function patchColumn.
export function patchColumn(pluginDesc: IPluginDesc, colDesc: IAdditionalColumnDesc, rows: IScoreRow<any>[], col: Column) {
  if (colDesc.type === 'number' && col instanceof NumberColumn) {
    // Calculate something using the rows, and set it on the column...
  }
}
  1. Now, each time a score is loaded, your patcher will be called (after the internal patching) to allow your updates to take place.

Copy link
Member

@thinkh thinkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rename the extension point to follow the new extension point naming schema. The rest looks fine to me.

@puehringer puehringer requested a review from thinkh October 28, 2019 12:37
Copy link
Member

@thinkh thinkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. It looks good now. 👍

@thinkh thinkh merged commit 8a610ee into develop Oct 28, 2019
@thinkh thinkh deleted the mpuehringer/233_column_patcher_ext branch October 28, 2019 14:56
@thinkh thinkh added release: minor PR merge results in a new minor version type: feature New feature or request labels Nov 22, 2019
@thinkh thinkh mentioned this pull request Nov 22, 2019
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: minor PR merge results in a new minor version type: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants