Socket
Socket
Sign inDemoInstall

node-barefoot

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-barefoot - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

3

CHANGES.md
# Changes
## 0.0.8
* Introduction of [Debug](https://github.com/visionmedia/debug) for code flow analysis. Thx @mweibel :)
## 0.0.7

@@ -3,0 +6,0 @@ * Introduced promises for rendering `Views` using [Q](https://github.com/kriskowal/q)

14

lib/apiadapter.js

@@ -14,10 +14,10 @@ /** Class: Barefoot.APIAdapter

*
* Thats the point where APIAdapter joins the game: It binds a bunch of API
* resources (actually just independant callback functions, each identified with
* Thats the point where APIAdapter joins the game: It binds a bunch of API
* resources (actually just independent callback functions, each identified with
* a unique URI) and wraps them into Express.JS routes to make them available to
* the clients. During startup (<Barefoot.Start.Server>), backbones sync
* function is automatically replaced with barefoots one to ensure that local
* API calls on the server are routed directly to the callbacks instead going
* a detour via HTTP/AJAX. For further details, have a look into APIAdapters
* server mixin: <Barefoot.APIAdapter.Server>.
* the clients. During startup (<Barefoot.Start.Server>), Backbone's sync
* function is automatically replaced with the one of Barefoot to ensure that
* local API calls on the server are routed directly to the callbacks instead
* going a detour via HTTP/AJAX. For further details, have a look into
* APIAdapters server mixin: <Barefoot.APIAdapter.Server>.
*

@@ -24,0 +24,0 @@ * You will probably touch the APIAdapter consciously only once: In your app

@@ -5,3 +5,3 @@ /** Mixin: Barefoot.CookieAdapter.Client

*
* Thie client <CookieAdapter> reads and writes the cookies directly from the
* The client <CookieAdapter> reads and writes the cookies directly from the
* browsers memory.

@@ -8,0 +8,0 @@ *

/** Mixin: Barefoot.Router.Client
* Client specific code for the <Barefoot.Router>. The complete view object
* restoration when receiving prerendered UI's from the server is handled in the
* <start> method.
* restoration when receiving pre-rendered UI's from the server is handled in
* the <start> method.
*

@@ -29,10 +29,10 @@ * See also:

*
* It handles mainly the restoration of the view objects after receiving an
* It handles mainly the restoration of the view objects after receiving an
* already rendered UI from the server. This process consists of the following
* steps:
*
* * If present, an instance of the main view is created and all events are
* * If present, an instance of the main view is created and all events are
* bound to the DOM elements.
* * The Barefoot.Router.Client.render method gets replaced temporarly to avoid
* rerendering already available content to the DOM. The replacement method
* * The Barefoot.Router.Client.render method gets replaced temporarily to avoid
* re-rendering already available content to the DOM. The replacement method
* only ensures that the necessary events get bound to the DOM.

@@ -80,3 +80,3 @@ *

// Temporarly replace the normal render function to allow restoring the
// Temporarily replace the normal render function to allow restoring the
// necessary view object. In case any router function calls navigate, that

@@ -105,3 +105,3 @@ // one gets replaced to.

*
* Paramteres:
* Parameters:
* (Barefoot.View) view - <Barefoot.View> to render into the DOM.

@@ -108,0 +108,0 @@ *

@@ -16,7 +16,7 @@ /** Mixin: Barefoot.Start.Client

* (Barefoot.Router) Router - A <Barefoot.Router> object. Important: This is
* is not an instance of the router, it is the
* is not an instance of the router, it is the
* "plain" object which can be used for running
* "new Router(...)".
* (Object) startOptions - This object literal is passed to the router when
* initalizing it.
* initializing it.
*/

@@ -23,0 +23,0 @@ function start(Router, APIAdapter, startOptions) {

@@ -14,5 +14,5 @@ /** Mixin: Barefoot.View.Client

* Binds all defined events of this view. In addition, all present subviews
* are iterated and a recusive call on delegateEventsOnSubviews is done.
* are iterated and a recursive call on delegateEventsOnSubviews is done.
*
* This method is a core part of the view object restoration when receiving
* This method is a core part of the view object restoration when receiving
* an already rendered UI from the server.

@@ -19,0 +19,0 @@ */

/** Class: Barefoot.Collection
* For the moment, barefoots collection does not introduce any new
* For the moment, the Barefoot collection does not introduce any new
* functionalities to Backbones collection. But to keep things straight when
* buildung your application with barefoot, <Barefoot.Collection> is also
* building your application with barefoot, <Barefoot.Collection> is also
* available :)

@@ -6,0 +6,0 @@ *

@@ -28,3 +28,3 @@ /** Class: Barefoot.DataStore

* In Depth:
* You may wonder how the DataStore accomplishs the data transfer from the
* You may wonder how the DataStore accomplishes the data transfer from the
* server to the client.

@@ -52,6 +52,6 @@ *

* with the given identifier. This information is needed when serializing the
* DataStore for transfering data to the client.
* DataStore for transferring data to the client.
*
* You will not be able to serialize a store containing models which were not
* registrered before!
* registered before!
*

@@ -58,0 +58,0 @@ * Important:

/** Class: Barefoot.Model
* For the moment, barefoots model does not introduce any new
* For the moment, the Barefoot model does not introduce any new
* functionalities to Backbones model. But to keep things straight when
* buildung your application with barefoot, <Barefoot.Model> is also
* building your application with barefoot, <Barefoot.Model> is also
* available :)

@@ -6,0 +6,0 @@ *

/** Class: Barefoot.Router
* The barefoot router extends the default backbone router by applying
* environment specific mixins to it
* The barefoot router extends the default backbone router by applying
* environment specific mixins to it
*

@@ -32,9 +32,9 @@ * For further information, please refer to the regarding environment specific

* > });
* The following sections discuss specific aspects/differences of this code
* The following sections discuss specific aspects / differences of this code
* snippet in comparison to a common Backbone application.
*
* Introduction of Barefoot.Router.render:
* If you want barefoot to render a view for you, do *never* call the
* If you want barefoot to render a view for you, do *never* call the
* <Barefoot.View> render function on yourself. Make sure you use the render
* function which is provided from <Barefoot.Router> (In the example:
* function which is provided from <Barefoot.Router> (In the example:
* "this.render(new HomeView());").

@@ -45,3 +45,3 @@ * This way ensures that the view is rendered properly on the server but also

* The Main View:
* You have the option to define a "main view". Understand this as a
* You have the option to define a "main view". Understand this as a
* <Barefoot.View> object which contains all common view objects like

@@ -48,0 +48,0 @@ * navigation bars, footer etc.

@@ -7,3 +7,3 @@ /** Mixin: Barefoot.APIAdapter.Server

*
* The creation of the Express.JS routes is done on initalization. The mapping
* The creation of the Express.JS routes is done on initialization. The mapping
* of server-side API calls is executed during runtime.

@@ -37,3 +37,4 @@ *

, 'read': 'get'
};
}
, debug = require('debug')('barefoot:server:apiadapter');

@@ -78,2 +79,4 @@

, errorHandler, callbacks) {
debug('processing callbacks (url: `%s`, namedRouteParameters: `%s`,' +
' data: `%j`)', req.url, namedRouteParameters, data);

@@ -156,3 +159,7 @@ var callbackScope = {

function createExpressJsCallback(successHandler, errorHandler, callbacks) {
debug('creating express.js callback');
return function handler(req, res) {
debug('express.js callback called for url `%s`', req.url);
processCallbacks(

@@ -207,2 +214,4 @@ _.values(req.params)

function createExpressJsRoute(url, callbacks, expressJsMethod, app) {
debug('creating express.js route for url `%s`', url);
var self = this

@@ -316,3 +325,3 @@ , expressJsHandler = createExpressJsCallback(

* contained in apiRoutes. If a route is found, the routes regex is used to
* extract any parameters from the url. These parameters are contained in the
* extract any parameters from the URL. These parameters are contained in the
* params argument afterwards.

@@ -338,2 +347,4 @@ *

function matchRoute(method, url, apiRoutes, params) {
debug('matching route method %s with url %s', method, url);
var routes = apiRoutes[method]

@@ -353,2 +364,3 @@ , matchedRoute;

}
debug('matched route `%j`', matchedRoute);

@@ -375,2 +387,4 @@ return matchedRoute;

function addRoute(method, url, callbacks) {
debug('adding route (method: `%s`, url: `%s`)', method, url);
var urlParamKeys = []

@@ -421,7 +435,7 @@ , regexp = urlRegexp(url, urlParamKeys, true, true);

*
* It tries to match the given url with a registered route for the given
* It tries to match the given URL with a registered route for the given
* httpMethod. If found, the route callback(s) is/are invoked using
* <processCallbacks>.
*
* If the data argument contains any information, that stuf gets passed to the
* If the data argument contains any information, that stuff gets passed to the
* callback. If the options argument contains a success or error element, these

@@ -446,2 +460,5 @@ * functions are called by the callback in case of success or failure.

function dispatchLocalApiCall(httpMethod, url, data, options) {
debug('dispatching local api call (httpMethod: `%s`, url: `%s`)'
, httpMethod, url);
var self = this

@@ -514,3 +531,3 @@ , params = {}

* Instead going the detour over an AJAX request, this implementation of sync
* calls the API callback directly by resolving the models url with the present
* calls the API callback directly by resolving the models URL with the present
* apiRoutes.

@@ -523,3 +540,3 @@ *

* (String) method - A method (create, update, patch, delete or read) which
* will be used to resolve the models url properly.
* will be used to resolve the models URL properly.
* (Backbone.Model) model - The model which wants to be synced. Can also be

@@ -536,2 +553,5 @@ * an instance of Backbone.Collection.

debug('syncing (method: `%s`, httpMethod: `%s`, url: `%s`, model: `%j`)'
, method, httpMethod, url, model);
if(_.isUndefined(url)) {

@@ -538,0 +558,0 @@ throw new Error('No url present for syncing!', model, options);

@@ -17,3 +17,4 @@ /** Mixin: Barefoot.CookieAdapter.Server

*/
var _ = require('underscore');
var _ = require('underscore')
, debug = require('debug')('barefoot:server:cookieadapter');

@@ -31,2 +32,4 @@

function get(key) {
debug('getting `%s`', key);
var value;

@@ -48,2 +51,4 @@ if(this.cookies && _.has(this.cookies, key)) {

function set(key, value) {
debug('setting `%s` to `%j`', key, value);
if(_.isUndefined(this.cookies)) {

@@ -50,0 +55,0 @@ this.cookies = {};

@@ -11,3 +11,4 @@ /** Mixin: Barefoot.DataStore.Server

*/
var _ = require('underscore');
var _ = require('underscore')
, debug = require('debug')('barefoot:server:datastore');

@@ -19,4 +20,4 @@ /** Function: toJSON

* Beside the actual data, this object contains meta information to accomplish
* a proper deserialisation with <Barefoot.DataStore.Client.parse>. This means,
* the DataStore can completly restore its content from a given serialized
* a proper deserialization with <Barefoot.DataStore.Client.parse>. This means,
* the DataStore can completely restore its content from a given serialized
* version of itself, including correct model and collection types.

@@ -56,2 +57,4 @@ *

debug('to json `%j`', serializedStore);
return serializedStore;

@@ -58,0 +61,0 @@ }

@@ -8,3 +8,5 @@ /** Mixin: Barefoot.Router.Server

var _ = require('underscore')
, debug = require('debug')('barefoot:server:router')
, cheerio = require('cheerio')
, winston = require('winston')
, Q = require('q')

@@ -14,4 +16,11 @@ , CookieAdapter

/** Function: toString
* String representation of this module.
*/
function toString() {
return 'Router.Server';
}
/** Function: preInitialize
* This function is called before any intialization or constructor of the
* This function is called before any initialization or constructor of the
* <Barefoot.Router> is executed. It expects that the passed options object

@@ -21,3 +30,3 @@ * contains the following elements:

* app - An Express.JS app
* layoutTemplate - The minimal HTML skeleton to render the applictation into.
* layoutTemplate - The minimal HTML skeleton to render the application into.
* Example: "<html><head></head><body></body></html>"

@@ -34,2 +43,4 @@ * startExpressApp - A callback function which initiates the actual startup of

function preInitialize(options) {
debug('pre initialize');
this.app = options.app;

@@ -43,3 +54,3 @@ this.layoutTemplate = options.layoutTemplate;

/** Function: route
* This replacemente for the route function of Backbone.Router ensures that each
* This replacements for the route function of Backbone.Router ensures that each
* route defined in the router is added to the Express.JS app.

@@ -60,2 +71,4 @@ *

function route(routeUri) {
debug('route `%s`', routeUri);
var self = this

@@ -70,2 +83,4 @@ , Barefoot = require('../')();

return self.app.get('/' + routeUri, function(req, res) {
debug('request to `/%s`', routeUri);
var callback = self[self.routes[routeUri]]

@@ -114,2 +129,4 @@ , cookieAdapter = new CookieAdapter({ cookies: req.cookies })

function navigate(routeUri) {
debug('redirecting to `%s`', routeUri);
this.res.redirect(routeUri);

@@ -128,3 +145,3 @@ }

* <Barefoot.DataStore> is checked. If present, its content gets serialized into
* a script DOM element so the client can proberly deserialize its state
* a script DOM element so the client can properly deserialize its state
* afterwards. See <Barefoot.Router.Client.start> for the deserialization code.

@@ -142,2 +159,4 @@ *

function render(view) {
debug('render');
var self = this

@@ -147,2 +166,4 @@ , $;

function initDOM() {
debug('init DOM');
$ = cheerio.load(self.layoutTemplate);

@@ -152,2 +173,4 @@ }

function renderMainView() {
debug('render main view');
var promise;

@@ -166,2 +189,4 @@

function renderView() {
debug('render view');
view.$ = $;

@@ -174,2 +199,4 @@ view.$el = view.selectDOMElement($);

function serializeDataStore() {
debug('serialize data store');
if(!_.isUndefined(self.dataStore) &&

@@ -186,6 +213,15 @@ _.keys(self.dataStore.registeredModels).length > 0) {

function writeHTTPResponse() {
debug('write http response');
self.res.send($.html());
}
function writeHTTPError() {
function writeHTTPError(err) {
winston.log('error', 'Uncatched HTTP Error', {
source: toString()
, err: err.toString() || err
, stack: err.stack || undefined
});
debug('write http error');
self.res.send(500);

@@ -205,2 +241,4 @@ }

function start() {
debug('start');
this.startExpressApp(this.app);

@@ -207,0 +245,0 @@ }

@@ -9,7 +9,8 @@ /** Mixin: Barefoot.Start.Server

, fs = require('fs')
, browserify = require('browserify-middleware');
, browserify = require('browserify-middleware')
, debug = require('debug')('barefoot:server:start');
/** PrivateFunction: getServerOnlyFiles
* Returns an array with absolute paths to the files contianed in the server
* subfolder.
* Returns an array with absolute paths to the files contained in the server
* sub folder.
*

@@ -30,3 +31,3 @@ * Returns:

/** PrivateFunction: prepareBrowserify
* Adds the browserify middleware the the given express.js app.
* Adds the Browserify middleware the the given express.js app.
*

@@ -62,3 +63,3 @@ * Parameters:

* On start on the server, this function creates an <APIAdapter> if apiRoutes
* are present in the startOptions. Further the actual <Barefoot.Router> is
* are present in the startOptions. Further the actual <Barefoot.Router> is
* created an started using <Barefoot.Router.Server.start>.

@@ -71,9 +72,11 @@ *

* (Barefoot.Router) Router - A <Barefoot.Router> object. Important: This is
* is not an instance of the router, it is the
* is not an instance of the router, it is the
* "plain" object which can be used for running
* "new Router(...)".
* (Object) startOptions - This object literal is passed to the router when
* initalizing it.
* initializing it.
*/
function start(Router, APIAdapter, startOptions) {
debug('Starting server');
if(!_.has(startOptions, 'app')) {

@@ -80,0 +83,0 @@ throw new Error('Missing "app" property in "startOptions"! Please ' +

/** Mixin: Barefoot.View.Server
* Enhances the <Barefoot.View> class with server specific code fragmends.
* Enhances the <Barefoot.View> class with server specific code fragments.
* "Enhancing" is quite exaggerate: Actually it ensures that a few Backbone
* methods are replaced with an empty implementation since barefoot do not want
* them to query any DOM elements when rendering a view on the server. Following
* methods are overwridden:
* methods are overridden:
*

@@ -8,0 +8,0 @@ * * setElement(element)

@@ -43,3 +43,3 @@ /** Class: Barefoot.Util

/** Function: loadMixins
* Since Barefoot is runnable on server and client, this function returns
* Since Barefoot is runnable on server and client, this function returns
* environment specific code read from the "server" and "client" folder and

@@ -46,0 +46,0 @@ * returns the needed code fragments.

@@ -31,3 +31,3 @@ /** Class: Barefoot.View

* > });
* The following sections discuss specific aspects/differences of this code
* The following sections discuss specific aspects / differences of this code
* snippet in comparison to a common Backbone application.

@@ -44,3 +44,3 @@ *

* Subviews/Nested Views:
* You may be used to create your views subviews directly in the render
* You may be used to create the subviews of your views directly in the render
* function and call their render function there.

@@ -53,3 +53,3 @@ *

* * Barefoot can render views on its own on the server and the browser client
* * You do not take care of destroying your view hiearchy when rendering a new
* * You do not take care of destroying your view hierarchy when rendering a new
* view. Barefoot will handle this for you. (No more Zombies)

@@ -60,3 +60,3 @@ *

* Barefoot looks for a beforeRender or afterRender function and executes them
* before/after rendering your view automatically.
* before / after rendering your view automatically.
*

@@ -87,4 +87,4 @@ * If beforeRender or afterRender is invoked, a "resolve" and "rejected"

*
* These technique is widley known as "Promises". Barefoot uses the popular
* implementaion <Q at https://github.com/kriskowal/q> implementation of the
* These technique is widely known as "Promises". Barefoot uses the popular
* implementation <Q at https://github.com/kriskowal/q> implementation of the
* <Promises/A+ at http://promises-aplus.github.io/promises-spec/> spec.

@@ -95,10 +95,17 @@ *

* Please be aware you are not overwriting the <renderSubviews> and <render>
* method. This would break barefoots rendering mechanisms on the server and
* client.
* method. This would break the rendering mechanisms of Barefoot on the server
* and client.
*/
var _ = require('underscore')
, Backbone = require('backbone')
, Q = require('q');
, Q = require('q')
, util = require('./util');
if(util.getEnvironment() === 'server') {
var debug = require('debug')('barefoot:view');
} else {
var debug = function() {};
}
/** Function: addSubview

@@ -112,2 +119,3 @@ * Adds a Barefoot.View as subview of this view. Sets the parentView property

function addSubview(subview) {
debug('add subview `%s`', this.toString());
if(_.isUndefined(this.subviews)) {

@@ -126,6 +134,7 @@ this.subviews = [];

* Parameters:
* (Barefoot.View) subview - A <Barefoot.View> sbuview to remove from this
* (Barefoot.View) subview - A <Barefoot.View> subview to remove from this
* view
*/
function removeSubview(subview) {
debug('remove subview `%s`', this.toString());
subview.close();

@@ -149,2 +158,3 @@

function renderSubviews() {
debug('render subviews `%s`', this.toString());
var self = this

@@ -167,4 +177,4 @@ , $ = self.$;

* If you define a beforeRender or afterRender function in your <View>
* implementation, that function will be called before/after the actual
* rendering takes/took place.
* implementation, that function will be called before / after the actual
* rendering takes / took place.
*

@@ -181,5 +191,7 @@ * Attention:

function render() {
debug('render `%s`', this.toString());
var self = this;
function invokeBeforeRender() {
debug('invoke before render `%s`', self.toString());
var deferBeforeRender = Q.defer()

@@ -199,2 +211,3 @@ , resolve = deferBeforeRender.resolve

function invokeRender() {
debug('invoke render `%s`', self.toString());
if(!_.isUndefined(self.renderView)) {

@@ -206,2 +219,3 @@ self.renderView();

function invokeAfterRender() {
debug('invoke after render `%s`', self.toString());
var deferAfterRender = Q.defer()

@@ -237,2 +251,3 @@ , resolve = deferAfterRender.resolve

function selectDOMElement($) {
debug('select dom element `%s`', this.toString());
var domElement;

@@ -239,0 +254,0 @@

{
"name": "node-barefoot"
, "version": "0.0.7"
, "version": "0.0.8"
, "description": "Barefoot makes code sharing between browser and server reality. Write your application once and run it on both ends of the wire."

@@ -24,2 +24,3 @@ , "keywords": [

, "q": "~0.9.3"
, "debug": "~0.7.2"
}

@@ -26,0 +27,0 @@ , "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc