sharify
Easily share data between Browserify modules meant to run on the server and client.
Example
The following example shares a Backbone Model between the server and browser. However, this could be applied to any module shared server/client.
Inject some constant data on the server and mount sharify
var sharify = ;sharifydata = API_URL: 'http://artsy.net/api/v1' NODE_ENV: processenvNODE_ENV;app;
Use in a module that can run on the server or client
var Backbone = API_URL = dataAPI_URL; var Artwork = moduleexports = BackboneModel
Inject sharify script in the view
html body //- Adds `sharify.data` and a convenient `sd` short hand to locals if sharify.data.NODE_ENV == 'development' #debug-modal #scripts //- Make sure this is above your other scripts != sharify.script() script( src='/bundle.js' )
NOTE: Sharify will safely expose the sharify.data
and sd
globals to the client-side for the convenience of sharing templates server/client.
Use the shared module server/client
// server.jsvar Artwork = ; app
// client.jsvar Artwork = View = ; model: ;
Bootstrapping Request-level Data to the Client
You can use sharify to bootstrap dynamic data as well.
Inject data into the sharify.data
local
var Artwork = ; app;
Require the data on the client
var Artwork = ARTWORK_JSON = dataARTWORK_JSON View = ; model: ARTWORK_JSON ;
Contributing
Please fork the project and submit a pull request with tests. Install node modules npm install
and run tests with make test
.
License
MIT