miguelcobain / ember-yeti-table

Yeti Table

Home Page:https://miguelcobain.github.io/ember-yeti-table

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

defining config without `theme` key errors

sumeetattree opened this issue · comments

Currently this line:

let configTheme = config ? config.theme : {};
let mergedTheme = merge.all([{}, DEFAULT_THEME, configTheme, this.get('theme') || {}]);

throws:

TypeError: Cannot convert undefined or null to object

Maybe we can assert that a toplevel key config.theme is defined?

Defining a theme in the config should be completely optional.
I didn't get that error in the dummy app. Did you add any config in your app?

Im thinking the line should be

let configTheme = config && config.theme ? config.theme : {} ;

when it executes the following line, config.theme could be undefined, the merge.all is having the problem.

Alternately you could do this

let configTheme = config ? config.theme :  undefined;
let mergedTheme = merge.all([{}, DEFAULT_THEME, configTheme || {}, this.get('theme') || {}]);

Which might make more sense since we are doing the || {} on the this.get("theme") as well

Yeah, I added this config:

    'ember-yeti-table': {
      table: 'table',
      sorting: {
        columnSortable:  'table-sortable',
        columnSorted: 'table-sorted',
        columnSortedAsc: 'table-sorted-asc',
        columnSortedDesc: 'table-sorted-desc',
      },

      pagination: {
        controls: 'table-pagination-controls',
        info: 'table-pagination-controls-page-info',
        pageSize: 'table-pagination-controls-page-size',
        next: 'table-pagination-controls-next',
        previous: 'table-pagination-controls-previous'
      }
    }

Notice the missing theme key at the top level. This is mostly an ease of use scenario. I think you should assert for it in case devs miss the said key

Adding the missing theme key fixed it.

Asserting it requires that the theme be specified in the config and that should be optional. Im not sure we want an assert there.

@sumeetattree the reason we can't do that is because a user might want to define other configs that aren't the theme in the future.

For example, in #22 we're thinking about being able to define a sortSequence property in the config. Defining it without defining a theme should be a completely valid use case, so we shouldn't assert.

I'm totally in favor of making this more explicit in the documentation, though.

Im thinking the line should be

let configTheme = config && config.theme ? config.theme : {} ;

when it executes the following line, config.theme could be undefined, the merge.all is having the problem.

Alternately you could do this

let configTheme = config ? config.theme :  undefined;
let mergedTheme = merge.all([{}, DEFAULT_THEME, configTheme || {}, this.get('theme') || {}]);

Which might make more sense since we are doing the || {} on the this.get("theme") as well

@miguelcobain I get that totally.

We could improve the documentation. I would suggest adding an example in the documentation showing how to include the config from /config/environment.js. I had to dig through the source to find out it's even possible to do that.

@miguelcobain Let me know if you'd like a pull request with the documentation change.

screen shot 2019-02-07 at 15 54 45

@sumeetattree @cah-briangantzler I wrote this up and am about to push it to master. Let me know if something isn't clear.

@miguelcobain This looks good!

I think this looks good