Skip to content

Commit

Permalink
Bump ember-cli-bable and import invoke action
Browse files Browse the repository at this point in the history
  • Loading branch information
joegaudet committed Apr 22, 2024
1 parent 5df4df0 commit e1bb995
Show file tree
Hide file tree
Showing 4 changed files with 21,933 additions and 4,023 deletions.
16 changes: 9 additions & 7 deletions addon/components/full-calendar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Ember from 'ember';
import layout from '../templates/components/full-calendar';
import { InvokeActionMixin } from 'ember-invoke-action';
import { Calendar } from '@fullcalendar/core';
import deepEqual from 'fast-deep-equal'
import deepEqual from 'fast-deep-equal';

const { assign, observer, computed, getOwner } = Ember;
import { computed, observer } from '@ember/object';
import { getOwner } from '@ember/application';
import Component from '@ember/component';
import { schedule } from '@ember/runloop';
import { InvokeActionMixin } from './invoke-action-mixin';

export default Ember.Component.extend(InvokeActionMixin, {
export default Component.extend(InvokeActionMixin, {
/////////////////////////////////////
// PROPERTIES
/////////////////////////////////////
Expand Down Expand Up @@ -160,7 +162,7 @@ export default Ember.Component.extend(InvokeActionMixin, {
const calendarEvents = this.getEvents();

const options =
assign(
Object.assign(
{},
calendarOptions,
calendarEvents
Expand Down Expand Up @@ -263,7 +265,7 @@ export default Ember.Component.extend(InvokeActionMixin, {

// create an event handler that runs the function inside an event loop.
actions[eventName] = (...args) => {
Ember.run.schedule('actions', this, () => {
schedule('actions', this, () => {
this.invokeAction(eventName, ...args, this.get('calendar'));
});
};
Expand Down
71 changes: 71 additions & 0 deletions addon/components/invoke-action-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug';
import { get } from '@ember/object';

const makeInvokeAction = ({ strict = false } = {}) => {
return (object, actionName, ...args) => {
assert('The first argument passed to invokeAction must be an object',
typeof object === 'object');

let action;
if (typeof actionName === 'string') {
action = get(object, actionName);
} else if (typeof actionName === 'function') {
action = actionName;
} else {
assert('The second argument passed to invokeAction must be a string as actionName or a function',
false);
}

if (typeof action === 'string') {
object.sendAction(actionName, ...args);
} else if (typeof action === 'function') {
return action(...args);
} else if (strict) {
assert(`No invokable action ${actionName} was found`, false);
}
};
};

const getActions = (object) => {
return object.actions ? object.actions : object._actions;
};

const makeInvoke = ({ strict = false } = {}) => {
return (object, actionName, ...args) => {
let actions = getActions(object);
let action = actions && actions[actionName];

if (typeof action === 'function') {
return action.call(object, ...args);
} else if (strict) {
assert(`No invokable action ${actionName} was found`, false);
}
};
};

export const invokeAction = makeInvokeAction();
export const strictInvokeAction = makeInvokeAction({ strict: true });

export const invoke = makeInvoke();
export const strictInvoke = makeInvoke({ strict: true });

export const InvokeActionMixin = Mixin.create({
invokeAction() {
return invokeAction(this, ...arguments);
},

strictInvokeAction() {
return strictInvokeAction(this, ...arguments);
},

invoke() {
return invoke(this, ...arguments);
},

strictInvoke() {
return strictInvoke(this, ...arguments);
}
});

export default invokeAction;
Loading

0 comments on commit e1bb995

Please sign in to comment.