Skip to content

Commit

Permalink
[release]
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr committed Aug 26, 2015
1 parent 9c08743 commit 8f662d5
Show file tree
Hide file tree
Showing 35 changed files with 1,450 additions and 1,267 deletions.
1,651 changes: 859 additions & 792 deletions dist/focus.js

Large diffs are not rendered by default.

55 changes: 42 additions & 13 deletions lib/application/action-builder.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
'use strict';

var dispatcher = require('../dispatcher');
var message = require('../message');

var _require = require('../network/error-parsing');

var manageResponseErrors = _require.manageResponseErrors;

var _require2 = require('lodash/lang');

var clone = _require2.clone;
var isArray = _require2.isArray;

/**
* Method call before the service.
* @param {Object} config - The action builder config.
*/
function _preServiceCall() {
var _data, _status;

var config = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

//There is a problem if the node is empty. //Node should be an array
var node = config.node;
var type = config.type;
var preStatus = config.preStatus;
var callerId = config.callerId;

var data = {};
var status = {};
// When there is a multi node update it should be an array.
if (isArray(node)) {
node.forEach(function (nd) {
data[nd] = null;
status[nd] = { name: preStatus, isLoading: true };
});
} else {
data[node] = null;
status[node] = { name: preStatus, isLoading: true };
}
//Dispatch store cleaning.
dispatcher.handleViewAction({
data: (_data = {}, _data[node] = undefined, _data),
data: data,
type: type,
status: (_status = {}, _status[node] = { name: preStatus }, _status.isLoading = true, _status),
status: status,
callerId: callerId
});
}
Expand All @@ -35,17 +52,28 @@ function _preServiceCall() {
function _postServiceCall(config, json) {
if (config === undefined) config = {};

var _data2, _status2;
var _ref;

var node = config.node;
var type = config.type;
var status = config.status;
var callerId = config.callerId;

var isMultiNode = isArray(node);
var data = isMultiNode ? json : (_ref = {}, _ref[node] = json, _ref);
var postStatus = { name: status, isLoading: false };
var newStatus = {};
if (isMultiNode) {
node.forEach(function (nd) {
newStatus[nd] = postStatus;
});
} else {
newStatus[node] = postStatus;
}
dispatcher.handleServerAction({
data: (_data2 = {}, _data2[node] = json, _data2),
data: data,
type: type,
status: (_status2 = {}, _status2[node] = { name: status }, _status2.isLoading = false, _status2),
status: newStatus,
callerId: callerId
});
}
Expand Down Expand Up @@ -88,13 +116,14 @@ module.exports = function actionBuilder(config) {
}*/
//Exposes a function consumes by the compoennt.
return function actionBuilderFn(criteria) {
var conf = clone(config);
//It the callerId is not defined in the config, it is overriden with the form identifier.
config.callerId = config.callerId || this._identifier;
_preServiceCall(config);
return config.service(criteria).then(function (jsonData) {
return _postServiceCall(config, jsonData);
conf.callerId = conf.callerId || this._identifier;
_preServiceCall(conf);
return conf.service(criteria).then(function (jsonData) {
return _postServiceCall(conf, jsonData);
}, function (err) {
return _errorOnCall(config, err);
return _errorOnCall(conf, err);
});
};
};
9 changes: 2 additions & 7 deletions lib/application/built-in-store.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
'use strict';

var ApplicationStore = require('../store/application');
var instanciatedApplicationStore;

/**
* Built the store in order to the .
* @return {ApplicationStore} - An instanciated application store.
*/
module.exports = function builtInStore() {
if (!instanciatedApplicationStore) {
instanciatedApplicationStore = new ApplicationStore();
}
return instanciatedApplicationStore;
};
module.exports = new ApplicationStore();
71 changes: 43 additions & 28 deletions lib/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,51 @@

var React = require('react');
var dispatcher = require('../dispatcher');
//Empty compoennt.
var Empty = React.createClass({
displayName: 'Empty',

render: function render() {
return React.createElement('div', null);
}
/** @inheritdoc */
displayName: 'Empty',
/** @inheritdoc */
render: function render() {
return React.createElement('div', null);
}
});

module.exports = {
render: require('./render'),
builtInStore: require('./built-in-store'),
actionBuilder: require('./action-builder'),
clear: require('./clear'),
mountedComponents: require('./mounted-components'),
changeMode: function changeMode(newMode, previousMode) {
var mode = { newMode: newMode, previousMode: previousMode };
dispatcher.handleViewAction({ data: { mode: mode }, type: 'update' });
},
changeRoute: function changeRoute(newRoute) {
dispatcher.handleViewAction({ data: { route: newRoute }, type: 'update' });
},
clearCartridge: function clearCartridge() {
dispatcher.handleViewAction({
data: {
cartridgeComponent: { component: Empty },
barContentLeftComponent: { component: Empty },
summaryComponent: { component: Empty },
actions: { primary: [], secondary: [] }
},
type: 'update'
});
}
render: require('./render'),
builtInStore: require('./built-in-store'),
actionBuilder: require('./action-builder'),
clear: require('./clear'),
mountedComponents: require('./mounted-components'),
/**
* Change application mode.
* @param {string} newMode - New application mode.
* @param {string} previousMode - Previous mode.
*/
changeMode: function changeMode(newMode, previousMode) {
var mode = { newMode: newMode, previousMode: previousMode };
dispatcher.handleViewAction({ data: { mode: mode }, type: 'update' });
},
/**
* Change application route (maybe not the wole route but a route's group.)
* @param {string} newRoute - new route name.
*/
changeRoute: function changeRoute(newRoute) {
dispatcher.handleViewAction({ data: { route: newRoute }, type: 'update' });
},
/**
* Clear the application's header.
* @return {[type]} [description]
*/
clearHeader: function clearHeader() {
dispatcher.handleViewAction({
data: {
cartridgeComponent: { component: Empty },
barContentLeftComponent: { component: Empty },
summaryComponent: { component: Empty },
actions: { primary: [], secondary: [] }
},
type: 'update'
});
}
};
55 changes: 26 additions & 29 deletions lib/application/render.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
'use strict';
/*global document*/
//dependencies
'use strict';

var React = require('react');
var keys = require('lodash/object/keys');
/**
* Map containing all the mounted components.
* @type {Object}
*/
var mountedComponents = require('./mounted-components');

var clearComponent = require('./clear');

/**
* Render a react component in a DOM selector.
* @param {object} component - A react component.
* @param {string} selector - A selector on a DOM node.
* @param {object} options - Options for the component rendering.
*/
* Render a react component in a DOM selector.
* @param {object} component - A react component.
* @param {string} selector - A selector on a DOM node.
* @param {object} options - Options for the component rendering.
*/
module.exports = function renderComponent(component, selector, options) {
options = options || {};
// Clear a potential previously mounted component
clearComponent(selector);
var targetDOMContainer = document.querySelector(selector);
if (!targetDOMContainer) {
throw new Error('You are trying to render a component in a DOM element which is not existing, your selector is ' + selector);
}
// Render the component
var mountedComponent = React.render(React.createElement(component, options.props, options.data), targetDOMContainer);
//Save the fact that a component is mounted.
mountedComponents[selector] = mountedComponent;
console.info('Mounted components : ', keys(mountedComponents));
return mountedComponent;
options = options || {};
// Clear a potential previously mounted component
clearComponent(selector);
var targetDOMContainer = document.querySelector(selector);
if (!targetDOMContainer) {
throw new Error('You are trying to render a component in a DOM element which is not existing, your selector is ' + selector);
}
// Render the component
var mountedComponent = React.render(React.createElement(component, options.props, options.data), targetDOMContainer);
//Save the fact that a component is mounted.
mountedComponents[selector] = mountedComponent;
console.info('Mounted components : ', keys(mountedComponents));
return mountedComponent;
};
/*
Exemple
var render = Focus.application.render;
var MyComponent = require('./my-component');
render(MyComponent, 'div.component-container', {props: {id: '12'}});
*/
Exemple
var render = Focus.application.render;
var MyComponent = require('./my-component');
render(MyComponent, 'div.component-container', {props: {id: '12'}});
*/
47 changes: 18 additions & 29 deletions lib/component/builder.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
"use strict";
'use strict';

var React = require('react');
var assign = require('object-assign');
//var isObject = require('lodash/lang/isObject');
//var isFunction = require('lodash/lang/isFunction');

/**
* Create a component with a mixin except id the component is mixin only.
* @param {object} mixin - The component mixin.
* @param {Boolean} isMixinOnly - define if the component is a mixin only.
* @return {object} - {component} the built react component.
*/
* Create a component with a mixin except id the component is mixin only.
* @param {object} mixin - The component mixin.
* @param {Boolean} isMixinOnly - define if the component is a mixin only.
* @return {object} - {component} the built react component.
*/
function createComponent(mixin, isMixinOnly) {
if (isMixinOnly) {
return undefined; //Error('Your class publish a mixin only...');
}
return { component: React.createClass(mixin) };
if (isMixinOnly) {
return null;
}
return { component: React.createClass(mixin) };
}

/**
* Build a module with a mixin and a React component.
* @param {object} componentMixin - Mixin of the component.
* @param {boolean} isMixinOnly - Bolean to set .
* @return {object} {mixin: 'the component mixin', component: 'the react instanciated component'}
*/
module.exports = function (componentMixin, isMixinOnly) {

return assign({
mixin: componentMixin
/*extend: function extendMixin(properties){
if(isFunction(componentMixin)){
throw new Error('You cannot extend a mixin function');
}
if(!isObject(properties)){
throw new Error('properties should be an object');
}
return assign({}, componentMixin, properties);
},*/
}, createComponent(componentMixin, isMixinOnly));
* Build a module with a mixin and a React component.
* @param {object} componentMixin - Mixin of the component.
* @param {boolean} isMixinOnly - Bolean to set .
* @return {object} {mixin: 'the component mixin', component: 'the react instanciated component'}
*/
module.exports = function builder(componentMixin, isMixinOnly) {
return assign({ mixin: componentMixin }, createComponent(componentMixin, isMixinOnly));
};
3 changes: 2 additions & 1 deletion lib/component/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
'use strict';

module.exports = {
builder: require('./builder'),
types: require('./types')
Expand Down
Loading

0 comments on commit 8f662d5

Please sign in to comment.