npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsr-mocks

v2.0.5

Published

jsr-mocks =========

Downloads

3

Readme

jsr-mocks

a mock shim for javascript remoting

Use to test local versions of single page salesforce apps without deploying to server

install

bower install jsr-mocks#angular Configure jsr-mocks to expect a global object named configSettings with a property called mocks

'use strict';

angular.module('App', ['ngAnimate', 'ngSanitize', 'ui.router', 'jsrMocks'])
  

  .config(function ($stateProvider, $urlRouterProvider,jsrMocksProvider) {
    $stateProvider
      .state('home', {
        url: '/',
        templateUrl: 'app/main/main.html',
        controller: 'MainController'
      });

    $urlRouterProvider.otherwise('/');
    
    //configure jsr-mocks
    jsrMocksProvider.setMocks(configSettings.mocks);

  });
;

Now in your VF page, you must resolve the names of your Javascript Remote Actions.

<head>

	<link rel="stylesheet" href="/static/css/main.css" />
</head>

<div id="ready" class="ready">I am ready already</div>
<div id="ready2" class="ready"><img src="http://s25.postimage.org/ykwiwxw23/ajax_loader_2.gif" alt="loading"/></div>
<div id="ready3" class="ready"><img src="http://s25.postimage.org/ykwiwxw23/ajax_loader_2.gif" alt="loading"/></div>
<script src="/static/bower_components/jquery/dist/jquery.js"></script>
<script src="/static/js/myOtherModule.js"></script>
<!-- first resolve VF variables into configSettings, our only global object -->
<script>
var configSettings = {
	remoteActions: {
		myFunction :'{!$RemoteAction.MyCustomController.myFunction}',
		myOtherFunction :'{!$RemoteAction.MyCustomController.myOtherFunction}'
	},
	mocks :{
		'{!$RemoteAction.MyCustomController.myFunction}' : {
			timeout : 2000, //2 seconds with inline callback
			method : function(args){   
				console.log('args',args);
				return { message:  args[1]}
			}
		},
		'{!$RemoteAction.MyCustomController.myOtherFunction}' : {
			timeout : 3000, //3 seconds with named callback function
			method : myCallback
		}
	}
}; 

function myCallback(args){
	console.log('args',args);
	return { message:  args[1] + ' says the other callback'}
}
	
</script>
<!-- since this is not a VF page, we load a shim library instead for JSR calls -->
<script src="/static/bower_components/jsr-mocks/dist/jsr-mocks.provider.js"></script>
<!-- now our main script can call JSR methods in VF and mock methods in HTML Page with same syntax -->
<script src="/static/js/main.js"></script>

main.js can now look like this


angular.module('myModule', ['jsrMocks']) //inject dependency
  .config(function ($stateProvider, $urlRouterProvider, jsrMocksProvider){
    jsrMocksProvider.setMocks(configSettings.mocks);//point to global config variable (see html)
});

Now you can use the newly provided jsr method

jsr({
	method: configSettings.remoteActions.communityUserId, //required
        args: [patient.id],  //only required if function expects arguments
        options : {buffer: true, escape: true, timeout: 30000} //optional
}).then(function(communityUserId) {
        if (communityUserId) {
            patientTaskModal.patient.communityUserId = communityUserId;
            patientTaskModal.patientIsCommunityUser = true;
        }
        patientTaskModal.ready = true;
});

or factories can just include the jsrMocks object and override Visualforce selectively

'use strict';

angular.module('myModule').factory('PatientFactory',  PatientFactory );

function PatientFactory($q, $rootScope, $log, jsrMocks) {
    
	//insert the shim
    var Visualforce = jsrMocks;

	var factory = {
		GetPatient : GetPatient
	};

	return factory;

	function GetPatient (patientId) {
        var deferred = $q.defer();
        
        //always use namespace-safe jsr invocations
        Visualforce.remoting.Manager.invokeAction(
            configSettings.remoteActions.getPatient,
            patientId,//this is the first argument to jsr method
            function(result, event) {
                $rootScope.$apply(function() {
                    if (event.status) {
                    	deferred.resolve(result);
                    } else {
                    	deferred.reject(event);
                    }
                });
            }
        );
		//always return a promise when making async calls
        return deferred.promise;
	}



	
}