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.6 to 0.0.7

docs/search/PrivateFunctionsE.html

4

CHANGES.md
# Changes
## 0.0.7
* Introduced promises for rendering `Views` using [Q](https://github.com/kriskowal/q)
* The `beforeRender` and `afterRender` hook has a `resolve` and `reject` argument now. These make it possible to wait for asynchronous function calls. Perfect for populating models with data from the `APIAdapter` before proceed with the actual rendering.
## 0.0.6

@@ -3,0 +7,0 @@ * `APIAdapter.Server` uses [winston](https://github.com/flatiron/winston) for logging errors now

2

docs/javascript/searchdata.js

@@ -159,3 +159,3 @@ var indexSectionsWithContent = {

"D": false,
"E": false,
"E": true,
"F": false,

@@ -162,0 +162,0 @@ "G": true,

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

* "/contacts/:name" as key and callback functions as values.
* Using the passed Express.JS route-creation-function "binder" (app.post,
* Using the passed Express.JS route-creation-function "binder" (app.post,
* app.put etc.), an Express.JS route is created.
*
*
* Each route callback is wrapped into an Express.JS specific handler function
* connected to the route URI. Combined with the Express.JS body parser
* connected to the route URI. Combined with the Express.JS body parser
* middleware, the first argument of your callback will contain the body of the

@@ -183,3 +183,3 @@ * request. If your route defines any parameters ("/contacts/:id"), the specific

*
* Beside the return value of the callback, the wrapper function sends
* Beside the return value of the callback, the wrapper function sends
* automatically an HTTP OK (200) to the request creator. If the callback throws

@@ -444,3 +444,10 @@ * an error object, that object is inspected for an "httpStatusCode" property.

if(_.isUndefined(matchedRoute)) {
throw new Error('Could not resolve API route: ' + url);
if(_.has(options, 'error')) {
options.error(new Error('Could not resolve API route: ' + url));
} else {
winston.log('info', 'Could not resolve API route', {
source: toString()
, apiRoute: url
});
}
}

@@ -447,0 +454,0 @@

@@ -9,2 +9,3 @@ /** Mixin: Barefoot.Router.Server

, cheerio = require('cheerio')
, Q = require('q')
, CookieAdapter

@@ -14,3 +15,3 @@ , DataStore;

/** Function: preInitialize
* This function is called before any intialization or constructor of the
* This function is called before any intialization or constructor of the
* <Barefoot.Router> is executed. It expects that the passed options object

@@ -43,3 +44,3 @@ * contains the following elements:

*
* The route function ensures that you have access to all cookies from the
* The route function ensures that you have access to all cookies from the
* request via the cookieAdapter property of this router.

@@ -110,4 +111,2 @@ *

this.res.redirect(routeUri);
//var callback = this[this.routes[routeUri]];
//return callback.apply(this, _.values(this.req.query));
}

@@ -120,3 +119,3 @@

* Afterwards the presence of a main view object is checked. If available, that
* main view gets rendered into the DOM. In any case, the passed view gets
* main view gets rendered into the DOM. In any case, the passed view gets
* rendered.

@@ -135,5 +134,2 @@ *

*
* Returns:
*
*
* See also:

@@ -143,25 +139,53 @@ * * <route>

function render(view) {
var $ = cheerio.load(this.layoutTemplate);
var self = this
, $;
if(!_.isUndefined(this.mainView)) {
var clonedMainView = _.clone(this.mainView());
clonedMainView.$ = $;
clonedMainView.$el = clonedMainView.selectDOMElement($);
clonedMainView.render();
function initDOM() {
$ = cheerio.load(self.layoutTemplate);
}
view.$ = $;
view.$el = view.selectDOMElement($);
view.render();
function renderMainView() {
var promise;
if(!_.isUndefined(this.dataStore) &&
_.keys(this.dataStore.registeredModels).length > 0) {
var serializiedDataStore = JSON.stringify(this.dataStore.toJSON())
, javaScriptElement =
'<script>function deserializeDataStore(){' +
'return ' + serializiedDataStore + ';}</script>';
$('body').append(javaScriptElement);
if(!_.isUndefined(self.mainView)) {
var clonedMainView = _.clone(self.mainView());
clonedMainView.$ = $;
clonedMainView.$el = clonedMainView.selectDOMElement($);
promise = clonedMainView.render();
}
return promise;
}
return this.res.send($.html());
function renderView() {
view.$ = $;
view.$el = view.selectDOMElement($);
return view.render();
}
function serializeDataStore() {
if(!_.isUndefined(self.dataStore) &&
_.keys(self.dataStore.registeredModels).length > 0) {
var serializiedDataStore = JSON.stringify(self.dataStore.toJSON())
, javaScriptElement =
'<script>function deserializeDataStore(){' +
'return ' + serializiedDataStore + ';}</script>';
$('body').append(javaScriptElement);
}
}
function writeHTTPResponse() {
self.res.send($.html());
}
function writeHTTPError() {
self.res.send(500);
}
Q.fcall(initDOM)
.then(renderMainView)
.then(renderView)
.then(serializeDataStore)
.done(writeHTTPResponse, writeHTTPError);
}

@@ -168,0 +192,0 @@

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

* mixins.
*
*
* Environment Specific Mixins:

@@ -39,7 +39,8 @@ * - <Barefoot.View.Client>

* Barefoot overwrites backbones render() with its own version
* (see <Barefoot.View.Shared.render>) to accomplish hassle free view
* (see <Barefoot.View.Shared.render>) to accomplish hassle free view
* rendering, both on client and server.
*
*
* Subviews/Nested Views:
* You may be used to create your views subviews directly in the render
* You may be used to create your views subviews directly in the render
* function and call their render function there.

@@ -49,5 +50,4 @@ *

* functions. Use these functions inside the initialization function of your
* view.
* view. Managing subviews this way brings a few improvements:
*
* Managing subviews this way brings a few improvements:
* * Barefoot can render views on its own on the server and the browser client

@@ -57,2 +57,36 @@ * * You do not take care of destroying your view hiearchy when rendering a new

*
*
* beforeRender and afterRender hooks:
* Barefoot looks for a beforeRender or afterRender function and executes them
* before/after rendering your view automatically.
*
* If beforeRender or afterRender is invoked, a "resolve" and "rejected"
* argument is passed to them. These two functions are essential when using
* asynchronous calls which prepare the view for rendering or doing async
* cleanup work.
*
* Lets say you use the beforeRender hook to load some data from your
* <APIAdapter> into <Model>s. Since calls to the <APIAdapter> are async, you
* have to ensure that beforeRender does not finish until the api call is done
* and your data in place. The following example shows such a beforeRender
* implementation:
*
* > function beforeRender(resolve, reject) {
* > contactsCollection.fetch({
* > success: function() {
* > resolve();
* > }
* > });
* > console.log('Loading contacts from API...');
* > }
*
* This function will not "terminate" as soon as the console.log statement was
* executed. Barefoot will wait until you explicitly call the "resolve" function
* argument (or reject in case something went wrong).
*
* These technique is widley known as "Promises". Barefoot uses the popular
* implementaion <Q at https://github.com/kriskowal/q> implementation of the
* <Promises/A+ at http://promises-aplus.github.io/promises-spec/> spec.
*
*
* Attention:

@@ -64,3 +98,4 @@ * Please be aware you are not overwriting the <renderSubviews> and <render>

var _ = require('underscore')
, Backbone = require('backbone');
, Backbone = require('backbone')
, Q = require('q');

@@ -107,3 +142,3 @@

* Attention:
* *Do never* call this method on your own. <Barefoot.View.Shared.render>
* *Do never* call this method on your own. <Barefoot.View.Shared.render>
* invoces this method automatically when needed.

@@ -113,5 +148,5 @@ */

var self = this
,$ = self.$;
, $ = self.$;
_.each(self.subviews, function(subview) {
return Q.when(_.each(self.subviews, function(subview) {
subview.$ = $;

@@ -122,3 +157,3 @@ subview.$el = subview.selectDOMElement($);

subview.delegateEvents();
});
}));
}

@@ -144,15 +179,42 @@

function render() {
if(!_.isUndefined(this.beforeRender)) {
this.beforeRender();
var self = this;
function invokeBeforeRender() {
var deferBeforeRender = Q.defer()
, resolve = deferBeforeRender.resolve
, reject = deferBeforeRender.reject;
if(!_.isUndefined(self.beforeRender)) {
self.beforeRender(resolve, reject);
} else {
resolve();
}
return deferBeforeRender.promise;
}
if(!_.isUndefined(this.renderView)) {
this.renderView();
function invokeRender() {
if(!_.isUndefined(self.renderView)) {
self.renderView();
}
}
if(!_.isUndefined(this.afterRender)) {
this.afterRender();
function invokeAfterRender() {
var deferAfterRender = Q.defer()
, resolve = deferAfterRender.resolve
, reject = deferAfterRender.reject;
if(!_.isUndefined(self.afterRender)) {
self.afterRender(resolve, reject);
} else {
resolve();
}
return deferAfterRender.promise;
}
this.renderSubviews();
return invokeBeforeRender()
.then(invokeRender)
.then(invokeAfterRender)
.then(self.renderSubviews.bind(self));
}

@@ -159,0 +221,0 @@

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

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

, "winston": "~0.7.1"
, "q": "~0.9.3"
}

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

@@ -73,3 +73,6 @@ describe('View', function() {

it('should call beforeRender', function(done) {
view.beforeRender = done;
view.beforeRender = function(resolve) {
resolve();
done();
};
view.render();

@@ -84,3 +87,6 @@ })

it('should call afterRender', function(done) {
view.afterRender = done;
view.afterRender = function(resolve) {
resolve();
done();
}
view.render();

@@ -104,3 +110,3 @@ })

subview = new Barefoot.View({ el: 'nav' });
view.$ = function() {};

@@ -121,3 +127,3 @@ subview.renderView = function() {};

})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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