Hyper: How to get config value?

Created on 8 Mar 2018  路  2Comments  路  Source: vercel/hyper

I feel like an idiot asking this, but I've been trying to solve this for hours now.

For a plugin, I want to add styling depending on a config setting, in this case showWindowControls.
So if this is set to 'left', I want some different style added.

My attempt so far:

exports.decorateConfig = (config) => {
    const controlLeft = config.showWindowControls;

    // main styling
    return Object.assign({}, config, {
        css: `
            ${config.css || ''}
            [...]
        `
    })

    if(controlLeft == 'left') {
        // add some more css if `showWindowControls` is set to `'left'`
        return Object.assign({}, config, {
            css: `
                ${config.css || ''}
                [...]
            `
        })
    }
}

Any tips to get me in the right direction?

Question

All 2 comments

I think you just need to move this block if(controlLeft == 'left') {to be above the first return:

exports.decorateConfig = (config) => {
    const controlLeft = config.showWindowControls;

    if(controlLeft == 'left') {
        // add some more css if `showWindowControls` is set to `'left'`
        return Object.assign({}, config, {
            css: `
                ${config.css || ''}
                [...]
            `
        })
    }

    // main styling
    return Object.assign({}, config, {
        css: `
            ${config.css || ''}
            [...]
        `
    })
}

Let me know if that was it 馃憤 Otherwise I'll dig deeper 馃檶

Thanks, that worked!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sarneeh picture sarneeh  路  3Comments

laur1s picture laur1s  路  3Comments

aem picture aem  路  3Comments

eoinmurray picture eoinmurray  路  3Comments

rauchg picture rauchg  路  3Comments