Home

Awesome

#Native Calendar A promise wrapper for Cordova Calendar Plugin

Overall goal is to add an easier workflow to the calendar plugin and add some error checking that doesn't exist in the current plugin.

#Install

npm install --save native-calendar-api

#Example use:

The original api was callbacks and you couldn't call an operation before the last operation had finished. This made handling a large array of events difficult to manage. Using this api you can now do something like:

import CalendarApi from 'native-calendar-api';
import YourLogger from 'some-lib';

CalendarApi.setup('MyApp-', 'Custom Error Prefix:');

function sampleCreateFromArray(events) {
  return events.reduce((curr, next) => {
    return curr.then(() => {
      return CalendarApi.newEvent(next);
    });
  }, P.resolve());
}

sampleCreateFromArray(eventArray)
  .then(() => {
    // execute some cleanup of the events after they have been added
  })
  .catch((err) => {
    YourLogger.log(err);
  });

#Class NativeCalendar

##Properties

##Methods

###setup(titlePrefix, errorPrefix) (should be called after plugin is loaded)

Initiates the calendar and error properties. Will console.warn if window.plugin.calendar doesn't exist

###clearErrors()

Resets the error object. This should be called after the errors have been consumed.

###validDate(date)

###isValid(event) Used internally but can be called direction to valide your event objects

When this method is called it will return true if all fields are valid on the event object. If false is returned it will append the errors to the errors property. When used internally the promise will be rejected with the error messages.

###newEvent(event)

In the case that the event is invalid this will be rejected and return an error object with all the errors. You can then log this output to your production logger such as:

import CalendarApi from 'native-calendar-api';
import YourLogger from 'some-lib';

CalendarApi.setup('MyApp-', 'Custom Error Prefix:');

const invalidEvent = {};
CalendarApi.newEvent(invalidEvent).catch((err) => {
  YourLogger.log(err);
});

###deleteEvent(event)

In the case that the event is invalid this will be rejected and return an error object with all the errors. You can then log this output to your production logger such as:

import CalendarApi from 'native-calendar-api';
import YourLogger from 'some-lib';

CalendarApi.setup('MyApp-', 'Custom Error Prefix:');

const invalidEvent = {};
CalendarApi.deleteEvent(invalidEvent).catch((err) => {
  YourLogger.log(err);
});

###convertFindEventToDeleteEvent() Meant for internal use but can be used to convert an object returned from a find in the NativeCalendar to a valid event for deletion. This is an issue due to the fact that the plugin returns a string rather than a date object. Be careful using this as it will always return a valid object meaning if you pass it nothing you will get a valid Event back initiated to now with a duration of 0

###convertFindDateToJavaScriptDate(date) Converts a date string returned by the plugin into a valid JavaScript date.

###getDefaultBlankObject()

###asyncCreateEvent(event)

###asyncCreateEventWithOptions(event, options)

###asyncCreateEventInteractively(event)

###asyncCreateEventInteractivelyWithOptions(event, options)

###asyncFindEvent(event)

###asyncDeleteEventById(id)

###asyncFindEventWithOptions(event, options)

###asyncDeleteEvent(event)

###asyncListCalendars()

###asyncDeleteEventFromNamedCalendar(event, calendarName)