Giter Site home page Giter Site logo

Comments (5)

dschreij avatar dschreij commented on June 18, 2024

By the way, I see you provide the option to alter the method callbacks by overwriting them in the config object that can be passed to the component, so this issue is not a critical one. Still, wouldn't it be better to pass on all arguments of fullcalendar's events to vue event handlers?

from vue-fullcalendar.

dschreij avatar dschreij commented on June 18, 2024

Well, that is harder than it seemed, as it is really difficult to get the context of the function right. It is very hard to let self and this point to the vue-calendar component, and thus to call the $emit function to fire the appropriate events.

I had to put this in the config object that is passed from the parent component into vue-fullecalendar to get this to work:

config:{
	eventDrop: (event, delta, removeFunc) => {
		this.$refs.calendar.$emit('event-drop', event, delta, removeFunc);
	},
	eventResize: (event, delta, removeFunc) => {
		this.$refs.calendar.$emit('event-resize', event, delta, removeFunc);
	},
}

where $refs.calendar points to the vue-calendar component

from vue-fullcalendar.

BrockReece avatar BrockReece commented on June 18, 2024

Hi @dschreij

Yeah I am always open to PR's and I agree that it would be useful.

As for your third message, shorthand functions do something magic with the scope behind the scenes, it might be easier to pass through a traditional function with a bind method pointing towards this.$refs.calendar but I guess I don't really see why you would want to scope the calendar component anyway?

Cheers
Brock

from vue-fullcalendar.

dschreij avatar dschreij commented on June 18, 2024

Hi Brock,

The reason for my current solution using shorthands is that I haven't been able to get access to the vue component and its methods (such as $emit) when passing these functions in the config object. I do need to scope the calendar component to get access to its $emit function, am I right?
I did play around with bind() but wasn't able to set the this reference to the full-calendar component.
I tried:

config:{
	eventDrop: (function(event, delta, removeFunc) {
		this.$emit('event-drop', event, delta, removeFunc);
	}).bind(this.$refs.calendar),
	eventResize: function (event, delta, removeFunc) {
		this.$emit('event-resize', event, delta, removeFunc);
	}).bind(this.$refs.calendar),
}

but this results in this being undefined. This is probably due to generating the config object in the data() function instead of created() or mounted() and as such, the components haven't been properly mounted and referenced yet.
I also played around referencing this in a self var (like you did), but to no avail.

I think the cleanest way of realising this, is to pass all these arguments through the default built-in functions, so I'll send you a PR shortly.

from vue-fullcalendar.

BrockReece avatar BrockReece commented on June 18, 2024

@dschreij

Yeah, I think you are right that my suggestion would have only worked on a properly mounted component.

Thanks, I appreciate your help.
Brock

from vue-fullcalendar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.