Skip to content

Commit

Permalink
fix: use plugin name property as preferences key
Browse files Browse the repository at this point in the history
  • Loading branch information
joelamb committed Oct 9, 2023
1 parent 3de2542 commit 01f5fd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions ember-headless-table/src/-private/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TrackedMap } from 'tracked-built-ins';

import type {
PluginClass,
PluginPreferenceFor,
PluginPreferences,
PreferencesAdapter as Adapter,
Expand Down Expand Up @@ -63,12 +64,13 @@ class TrackedPreferences {
return [...this.plugins.values()].every((pluginPrefs) => pluginPrefs.isAtDefault);
}

forPlugin(name: string) {
let existing = this.plugins.get(name);
forPlugin(klass: PluginClass<any>) {
let instance = Reflect.construct(klass, []) as PluginClass<any>;
let existing = this.plugins.get(instance.name);

if (!existing) {
existing = new TrackedPluginPrefs();
this.plugins.set(name, existing);
this.plugins.set(instance.name, existing);
}

return existing;
Expand Down
14 changes: 7 additions & 7 deletions ember-headless-table/src/plugins/-private/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const preferences = {
*/
delete(key: string) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.delete(key);
Expand All @@ -170,7 +170,7 @@ export const preferences = {
*/
get(key: string) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

return columnPrefs.get(key);
Expand All @@ -180,7 +180,7 @@ export const preferences = {
*/
set(key: string, value: unknown) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.set(key, value);
Expand All @@ -206,7 +206,7 @@ export const preferences = {

for (let column of table.columns) {
let prefs = column.table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.delete(key);
Expand Down Expand Up @@ -234,7 +234,7 @@ export const preferences = {
*/
delete(key: string) {
let prefs = table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);

existing.table.delete(key);

Expand All @@ -245,7 +245,7 @@ export const preferences = {
*/
get(key: string) {
let prefs = table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);

return existing.table.get(key);
},
Expand All @@ -254,7 +254,7 @@ export const preferences = {
*/
set(key: string, value: unknown) {
let prefs = table.preferences;
let existing = prefs.storage.forPlugin(klass.name);
let existing = prefs.storage.forPlugin(klass);

existing.table.set(key, value);

Expand Down
2 changes: 1 addition & 1 deletion ember-headless-table/src/plugins/column-resizing/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class TableMeta {
let tablePrefs = this.table.preferences;

for (let column of visibleColumnMetas) {
let existing = tablePrefs.storage.forPlugin('ColumnResizing');
let existing = tablePrefs.storage.forPlugin(ColumnResizing);
let columnPrefs = existing.forColumn(column.key);

columnPrefs.set('width', column.width.toString());
Expand Down

0 comments on commit 01f5fd0

Please sign in to comment.