Skip to content

mattwelch/makeDeferredProvider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Augment Visualforce Remote Objects to provide promises.

Setup

First, jQuery is required, as that's what provides the deferred/promises framework. After that's included, make sure makeDeferredProvider.js (or makePreferredProvider.min.js) is included.

Then, simply call

makeDeferredProvider("jsNameSpace");

where jsNameSpace is the namespace provided to the apex:remoteObjects VF tag. If no argument is provided for makeDeferredProvider, the default is SObjectModel, just like the remoteObjects tag.

Use

The regular flow for Visualforce Remote Object is (per the release notes):

var wh = new SObjectModel.Warehouse();
        
// Use the Remote Object to query for 10 warehouse records
wh.retrieve({ limit: 10 }, function(err, records){
    if(err) alert(err.message);
    else {
		alert (records);
    }
});

Using promises, the flow is just a bit different:

var wh = SObjectModel.deferredObject('Warehouse');;
        
// Use the Remote Object to query for 10 warehouse records
var whp = wh.retrieve({ limit: 10 });

whp.then(
// The first function is invoked when the promise is successfully fulfilled
	function(records){
		console.log(records);
    },
// The second function is invoked when the promise is rejected
    function(err) {
    	console.log(err);
    }
});

That's a bit more verbose, and in this simple case, promises aren't worth the effort. Read up more here, or here to really start to get the advantages promises offer.

About

Visualforce Remote Objects modified to return promises

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published