Skip to content

Commit

Permalink
fix: adjustments to new tabulator API
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyom Melichow committed Aug 31, 2023
1 parent 91d162c commit d158d61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 3 additions & 7 deletions addon/components/ember-tabulator.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class EmberTabulatorComponent extends Component {
instance = undefined;
@tracked instance;

@action
setInstance(instance) {
this.instance = instance;
}

@action
updateData() {
this.instance?.setData(this.args.data);
}
}
13 changes: 10 additions & 3 deletions addon/modifiers/-private/ember-tabulator-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ export default class EmberTabulatorInitModifier extends Modifier {
}

modify(element, [options], { onUpdate }) {
this.tabulator?.destroy();
this.tabulator = new Tabulator(element, options);
onUpdate?.(this.tabulator);
if (!this.tabulator) {
this.tabulator = new Tabulator(element, {
reactiveData: true,
...options,
});
options.events?.forEach((event) => {
this.tabulator.on(event.name, event.callback);
});
onUpdate?.(this.tabulator);
}
}
}
6 changes: 5 additions & 1 deletion addon/templates/components/ember-tabulator.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
...attributes
{{did-update this.updateData @data}}
{{-private/ember-tabulator-init this.args onUpdate=this.setInstance}}
/>
>
{{#if (has-block)}}
{{yield this.instance}}
{{/if}}
</div>

0 comments on commit d158d61

Please sign in to comment.