Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Logger throws error when Tagify used as module #1311

Closed
3 tasks done
Brakebein opened this issue Apr 1, 2024 · 1 comment
Closed
3 tasks done

New Logger throws error when Tagify used as module #1311

Brakebein opened this issue Apr 1, 2024 · 1 comment
Labels

Comments

@Brakebein
Copy link

Prerequisites

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

💥 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 ↑).

  • What is the expected behavior?
    When the script enters code where Tagify.logger is supposed to print some logs, no error should be thrown. For example, tag element doesn't exist in getSetTagData().

  • What is happening instead?
    An error is thrown at the point where Tagify.logger is called.

  • What error message are you getting?
    ReferenceError: Tagify is not defined

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 yairEO added the Bug label Apr 4, 2024
@yairEO
Copy link
Owner

yairEO commented Apr 8, 2024

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

@yairEO yairEO closed this as completed Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants