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 configure property log or onMatched #340

Open
DaddyWarbucks opened this issue Apr 21, 2022 · 0 comments
Open

New configure property log or onMatched #340

DaddyWarbucks opened this issue Apr 21, 2022 · 0 comments

Comments

@DaddyWarbucks
Copy link

DaddyWarbucks commented Apr 21, 2022

Please forgive me if this is already available. I did search issues, PR's, and code but did not see a way to handle this.

Is your feature request related to a problem? Please describe.
The problem I would like to solve is two fold.
1 - I would like to allow more verbose logging in the production build. I understand how/why the debug and verbose logging are removed from the production build. But, I have a staging environment where I would like to be able to view the logs of the users in that environment.
2 - I would like to be able to "toast" (or in some way display) matched sequences and display their keyMap data. This may also help alleviate the problem 1. For example, toast("You pressed ${sequence} - ${name}, ${description}"). Even though verbose/debug logging is disabled in the production build and this would not be as detailed, I can get what I need out of this.

Describe the solution you'd like
Allow the user to pass in a log property (or perhaps onMatched is a better name? This could technically be used for cases other than logging) to the config function. This log property would be a function with the signature (keyMapData) => {}. It would be up to the developer to do whatever they want with this data. And this would be called somewhere around

Another approach would be to allow an onMatched callback to handler functions. For example,

const handlers = {
  MY_EVENT: (event, onMatched) => {
    onMatched((keyMapData) => {
      const message = `You pressed ${keyMapData.sequence} - ${keyMapData.name}, ${keyMapData.description}`
      toast.info(message);
    })
  }
}

Describe alternatives you've considered
Problem 1 - I have considered requiring different builds based on my own environment setting. But I am unclear of to get the development build?
Problem 2 - There are not really any alternatives. I have considered manually logging in the handlers functions, but those functions only have access to the event, not the matched keyMapData

Additional context
An example

configure({
  log: (keyMapData) => {
    if (MY_ENV !== 'production') {
      // Allows me to view some basic hotkeys info
      // in staging, testing, dev environments.
      myLogger.log(keyMapData);
    }
    
    // I could also choose to display this info to the user
    const message = `You pressed ${keyMapData.sequence} - ${keyMapData.name}, ${keyMapData.description}`
    toast.info(message);

    
    // Maybe I could encode some "level" in the group like "warn:list"
    const [level, group] = keyMapData.group.split(':');
    toast[level](message);
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant