Created
May 6, 2015 13:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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