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

feat(Event): standard evt obj emulates native Event #726

Merged
merged 7 commits into from Aug 4, 2017

Conversation

Projects
None yet
3 participants
@alexsasharegan
Contributor

alexsasharegan commented Jul 23, 2017

Stripped down version of browser Event object for use in component events that offer some kind of preventDefault behavior implemented by BootstrapVue.

  • Adds a BvEvent class.

Example usage

// Inside modal.vue
{
  methods: {
    handleOkayClick(e) {
      this.$emit("ok", new BvEvent("ok", {
        nativeEvent: e,
        target: e.target,
        vueTarget: this,
      }))
    }
  }
}

// Listener
function handleOkay(e) {
  if (someCondition) {
    // Stops modal from closing
    e.preventDefault()
  }
}
@tmorehouse

This comment has been minimized.

Member

tmorehouse commented Jul 23, 2017

I'll be taking advantage of this in my b-form-tinyme control 😄

@alexsasharegan

This comment has been minimized.

Contributor

alexsasharegan commented Jul 23, 2017

Note: I removed the e.cancel alias. I originally placed it in there because that's the modal event obj signature, but I think it's better if that alias is implemented in modal.vue. Then it can be deprecated for e.preventDefault.

@tmorehouse

This comment has been minimized.

Member

tmorehouse commented Jul 23, 2017

Yep, I agree. The e.cancel() is specific to modal.

Once I get the modal transition stuff finished, I'll update the pseudo event to use BvEvent

@@ -23,7 +23,9 @@ export class BvEvent {
let defaultPrevented = false;
// Recreate preventDefault method. One way setter.
this.preventDefault = function preventDefault() {
defaultPrevented = true;
if (this.cancelable) {

This comment has been minimized.

@tmorehouse

tmorehouse Jul 23, 2017

Member

👍

I wonder if cancelable should default to false?

This comment has been minimized.

@alexsasharegan

alexsasharegan Jul 23, 2017

Contributor

Possibly. I figured we would be using this mostly in circumstances where we need the preventDefault capabilities, so those are inherently cancelable UI events. Then it would be easy to forget to pass cancelable: true. Not sure until we use it I guess.

This comment has been minimized.

@tmorehouse

tmorehouse Jul 23, 2017

Member

Yeah, true, 99% of the time this is used it would be for a preventDefault() use case.

This comment has been minimized.

@mosinve

mosinve Jul 24, 2017

Member

However, i think it would be right to have boolean props switchers initialized as false.

This comment has been minimized.

@tmorehouse

tmorehouse Jul 24, 2017

Member

Although these are properties of the event object, not the component, so true is not as bad.

This comment has been minimized.

@alexsasharegan

alexsasharegan Jul 24, 2017

Contributor

Right, in components we're after that <component bool-prop /> ease of use.

@tmorehouse tmorehouse added this to the v0.19.0 milestone Aug 2, 2017

@tmorehouse tmorehouse merged commit 919344b into master Aug 4, 2017

1 check passed

ci/circleci Your tests passed on CircleCI!
Details

@tmorehouse tmorehouse deleted the feat/events branch Sep 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment