yairEO / tagify

🔖 lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
https://yaireo.github.io/tagify/
Other
3.52k stars 433 forks source link

New Logger throws error when Tagify used as module #1311

Closed Brakebein closed 6 months ago

Brakebein commented 6 months ago

Prerequisites

💥 Demo Page

https://codesandbox.io/p/sandbox/simple-tagify-setup-logger-error-95nc55

Explanation

This applies only when Tagify is imported as module (see codesandbox ↑).

The problem is that Tagify is not globally available when used as module. You would need to put the logger logic into some extra file from where it gets imported into the other files. Something like:

// ./parts/Logger.js

export const Logger = {
    enabled: false,
    log(...args){ this.enabled && console.log('[Tagify]:', ...args) },
    warn(...args) { this.enabled && console.warn('[Tagify]:', ...args) }
};
// ./parts/Logger.js

import { Logger } from './Logger';

export function getSetTagData(tagElm, data, override){
    if( !tagElm ){
        Logger.warn("tag element doesn't exist",{tagElm, data})
        return data
    }
}
// ./Tagify.js

import { Logger } from './parts/Logger';

function Tagify( input, settings ){
    if( !input ){
        Logger.warn('input element not found', input)
    }
}

Tagify.logger = Logger;
yairEO commented 6 months ago

Fixed in https://github.com/yairEO/tagify/releases/tag/v4.23.0