1.2.1 • Published 10 years ago

funcsync v1.2.1

Weekly downloads
1
License
-
Repository
github
Last release
10 years ago

funcsync

Funcsync is a dependency-free extremely small library helping to exchange/synchronize functions between server and client side.

Prepares an object - might containing business logic as function - for sending in a text format (JSON for example) and vice versa.

Usage:

Server-side

Command line:

npm install funcsync

In node.js code:

var f = require('funcsync');
...
var obj = {
	"tab1":[
		function test1(){ console.log("My "); },
		function test2(){ console.log("dear "); }
	],
	"tab2":{ "test3": function(){ console.log("user:" + self.name); } }
};
...
f.stringify( obj ) // prepare the given object for sending
...
var fs = f.functify( obj, {nane:'Bob'} ); // retrieve functions from the obj received
fs.tab2.test3();

Bind context

The function functify has an optional second parameter: context. All function will access this context, through the variable name self while being executed.

This way you can bind a knockout.js viewmodel or anything you want and can access it via the name 'self'.

Client-side

In head

<script src='funcsync.min.js'></script>

In any script tag

funcsync.stringify( obj );

For a more complex scenario please find a complex project boilerplate: Division.js, where one business model is defined and maintained allowing you to use the same objects - including model and validation and computed values and associated functions - on both client side, server side and DB interaction!

1.2.1

10 years ago

1.2.0

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

11 years ago

1.1.0

11 years ago

1.0.9

11 years ago

1.0.8

11 years ago

1.0.7

11 years ago

1.0.6

11 years ago

1.0.5

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago