Skip to content

Add a name for all Vue instances. #63

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harish2704
Copy link
Contributor

It will help while debugging / performance analysis.
For eg: it will help while monitoring emitted events.

an example event logger will look like this

import Vue from "vue";
import debounce from "lodash/debounce";

class Logger {
  constructor( timeout ) {
    this.logs = {};
    this.flush = debounce(this._flush.bind(this), timeout );
  }
  log(by, event, payload) {
    this.logs[new Date().toISOString()] = { by, event, payload };
    this.flush();
  }
  _flush() {
    console.table(this.logs);
    this.logs = {};
  }
}
const logger = new Logger(1000);

Vue.prototype.$emit_orig = Vue.prototype.$emit;
Vue.prototype.$emit = function(event, payload) {
  logger.log( this.$options.name, event, JSON.stringify(payload) );
  this.$emit_orig(event, payload);
};

It will debugging / performance analysis.
For eg: it will help while monitoring emitted events.
@jarvelov
Copy link
Owner

This is an interesting suggestion approach. I've previously just added a console.log in the vfjsBusEventHandler function when I needed to troubleshoot events, but this would work for all events, even the ones emitted from the component. I could probably include this when using the development build if I make some changes to the webpack config. This will probably come in handy, thanks!

@harish2704
Copy link
Contributor Author

@jarvelov : Yes this will work for all events and thus, we can see an consolidated table of all emitted events in this way.

In fact, I did this to check whether my PR #62 is introducing any additional overhead for the library or not.

( Initially I tried fixing unique ID issue by simply using math.random in all element. But Using the above logging, i quickly realized that it was causing unwanted change - validate iterations . Then I changed the logic as mentioned in the current PR )

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

Successfully merging this pull request may close these issues.

2 participants