Skip to content

Instantly share code, notes, and snippets.

@idlework
Created May 6, 2015 13:05
Show Gist options
  • Save idlework/eec41385b81270157eb7 to your computer and use it in GitHub Desktop.
Save idlework/eec41385b81270157eb7 to your computer and use it in GitHub Desktop.
Example to show how I implemented the parse plugin(https://github.com/avivais/phonegap-parse-plugin) for Cordova. Out of context not very useable.
define(function (require) {
'use strict';
var cordovaPluginHelper = require('utils/cordovaPluginHelper');
var alertHelper = require('utils/alertHelper');
var LanguageReference = require('statics/LanguageReference');
return function Parse (plugin, completeCallback) {
withDeferred(initialize).always(completeCallback);
function initialize(deferred) {
var pushNotification = localStorage.getItem('pushNotification');
plugin.initialize(
pushNotification.applicationId,
pushNotification.clientKey,
deferred.resolve,
deferred.reject);
}
function subscribe (deferred) {
plugin.subscribe(
'channel-' + localStorage.getItem('clientId'),
deferred.resolve,
deferred.reject);
}
function withDeferred (func) {
var deferred = $.Deferred();
func(deferred);
return deferred.promise()
.fail(_.partial(alertHelper, LanguageReference.isParseProblem));
}
this.subscribeToPushChannel = withDeferred(subscribe);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment