Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest cujo releases #556

Merged
merged 1 commit into from
May 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions labs/architecture-examples/cujo/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Cujojs TodoMVC
# cujoJS TodoMVC

[Cujojs](http://cujojs.com) is an *architectural framework* for building highly modular, scalable, maintainable applications in Javascript. It provides architectural plumbing, such as modules (AMD and CommonJS), declarative application composition, declarative connections, and aspect oriented programming.
[cujoJS](http://cujojs.com) is an *architectural framework* for building highly modular, scalable, maintainable applications in Javascript. It provides architectural plumbing, such as modules (AMD and CommonJS), declarative application composition, declarative connections, and aspect oriented programming.

It is not a typical MV\* framework, although it does provide MV\* building blocks, such as templating and data binding.

## Highlights:

Some things we feel are interesting about cujojs's TodoMVC as compared to other implementations:
Some things we feel are interesting about cujoJS's TodoMVC as compared to other implementations:

* Application composition is separate from application logic
* Code is *highly* modular and organized into components, each consisting of
Expand Down
2 changes: 0 additions & 2 deletions labs/architecture-examples/cujo/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ TODO before release

* implement filters (using routing or another method)
* build javascript using cram.js
* use curl's preloads feature rather than .next() in run.js
* use a theme.css file
23 changes: 14 additions & 9 deletions labs/architecture-examples/cujo/app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
define(function () {
'use strict';

var textProp;
var textProp, updateRemainingCount;

/**
* Self-optimizing function to set the text of a node
*/
var updateRemainingCount = function () {
updateRemainingCount = function (nodes, value) {
// sniff for proper textContent property
textProp = 'textContent' in document.documentElement ? 'textContent' : 'innerText';

// resume normally
updateRemainingCount = setTextProp;
updateRemainingCount(arguments);
updateRemainingCount(nodes, value);
};

var setTextProp = function (nodes, value) {
function setTextProp(nodes, value) {
for (var i = 0; i < nodes.length; i++) {
nodes[i][textProp] = '' + value;
}
};
}

return {
/**
Expand Down Expand Up @@ -84,8 +84,10 @@ define(function () {
* Check/uncheck all todos
*/
toggleAll: function () {
var todos = this.todos;
var complete = this.masterCheckbox.checked;
var todos, complete;

todos = this.todos;
complete = this.masterCheckbox.checked;

todos.forEach(function (todo) {
todo.complete = complete;
Expand All @@ -99,8 +101,10 @@ define(function () {
* checked or unchecked.
*/
updateCount: function () {
var total = 0;
var checked = 0;
var total, checked;

total = 0;
checked = 0;

this.todos.forEach(function (todo) {
total++;
Expand Down Expand Up @@ -128,4 +132,5 @@ define(function () {
updateRemainingCount(this.remainingNodes, remaining);
}
};

});
3 changes: 1 addition & 2 deletions labs/architecture-examples/cujo/app/footer/template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<footer id="info">
<p>${edit}</p>
<p>${templateBy} <a href="http://github.com/sindresorhus">Sindre Sorhus</a></p>
<p>${createdBy} <a href="http://cujojs.com">cujojs</a></p>
<p>${createdBy} <a href="http://cujojs.com">cujoJS</a></p>
<p>${partOf} <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
2 changes: 1 addition & 1 deletion labs/architecture-examples/cujo/app/list/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<label></label>
<button class="destroy"></button>
</div>
<input class="edit" value="">
<form><input class="edit" name="text"></form>
</li>
</ul>
</section>
39 changes: 20 additions & 19 deletions labs/architecture-examples/cujo/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ define({
// Render and insert the create view
createView: {
render: {
template: { module: 'text!create/template.html' },
replace: { module: 'i18n!create/strings' }
template: { module: 'text!app/create/template.html' },
replace: { module: 'i18n!app/create/strings' }
},
insert: { first: 'root' }
},
Expand All @@ -26,9 +26,9 @@ define({
// data and mapping data fields to the DOM
listView: {
render: {
template: { module: 'text!list/template.html' },
replace: { module: 'i18n!list/strings' },
css: { module: 'css!list/structure.css' }
template: { module: 'text!app/list/template.html' },
replace: { module: 'i18n!app/list/strings' },
css: { module: 'css!app/list/structure.css' }
},
insert: { after: 'createView' },
bind: {
Expand All @@ -38,7 +38,7 @@ define({
text: 'label, .edit',
complete: [
'.toggle',
{ attr: 'classList', handler: { module: 'list/setCompletedClass' } }
{ attr: 'classList', handler: { module: 'app/list/setCompletedClass' } }
]
}
}
Expand All @@ -48,9 +48,9 @@ define({
// filters, and clear completed button.
controlsView: {
render: {
template: { module: 'text!controls/template.html' },
replace: { module: 'i18n!controls/strings' },
css: { module: 'css!controls/structure.css' }
template: { module: 'text!app/controls/template.html' },
replace: { module: 'i18n!app/controls/strings' },
css: { module: 'css!app/controls/structure.css' }
},
insert: { after: 'listView' }
},
Expand All @@ -59,8 +59,8 @@ define({
// is still fully internationalized.
footerView: {
render: {
template: { module: 'text!footer/template.html' },
replace: { module: 'i18n!footer/strings' }
template: { module: 'text!app/footer/template.html' },
replace: { module: 'i18n!app/footer/strings' }
},
insert: { after: 'root' }
},
Expand All @@ -81,10 +81,10 @@ define({

todos: {
create: {
module: 'cola/Hub',
module: 'cola/Collection',
args: {
strategyOptions: {
validator: { module: 'create/validateTodo' }
validator: { module: 'app/create/validateTodo' }
}
}
},
Expand All @@ -100,11 +100,11 @@ define({
// view controllers. Since this is a relatively simple application,
// a single controller fits well.
todoController: {
prototype: { create: 'controller' },
create: 'app/controller',
properties: {
todos: { $ref: 'todos' },

createTodo: { compose: 'parseForm | todos.add' },
createTodo: { compose: 'form.getValues | todos.add' },
removeTodo: { compose: 'todos.remove' },
updateTodo: { compose: 'todos.update' },

Expand All @@ -123,7 +123,8 @@ define({
'change:.toggle': 'updateTodo',
'click:#toggle-all': 'toggleAll',
'dblclick:label': 'todos.edit',
'change,focusout:.edit': 'todos.submit' // also need way to submit on [enter]
'change,focusout:.edit': 'todos.submit',
'submit:form': 'todos.submit'
},
controlsView: {
'click:#clear-completed': 'removeCompleted'
Expand All @@ -139,9 +140,9 @@ define({
}
},

parseForm: { module: 'cola/dom/formToObject' },
cleanTodo: { module: 'create/cleanTodo' },
generateMetadata: { module: 'create/generateMetadata' },
form: { module: 'cola/dom/form' },
cleanTodo: { module: 'app/create/cleanTodo' },
generateMetadata: { module: 'app/create/generateMetadata' },

toggleEditingState: {
create: {
Expand Down
29 changes: 14 additions & 15 deletions labs/architecture-examples/cujo/app/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
(function (curl) {
'use strict';

var config = {
baseUrl: 'app',
paths: {
theme: '../theme',
curl: '../lib/curl/src/curl'
},
pluginPath: 'curl/plugin',
curl({
main: 'wire!app/main',
packages: [
{ name: 'wire', location: '../lib/wire', main: 'wire' },
{ name: 'when', location: '../lib/when', main: 'when' },
{ name: 'aop', location: '../lib/aop', main: 'aop' },
{ name: 'cola', location: '../lib/cola', main: 'cola' },
{ name: 'poly', location: '../lib/poly', main: 'poly' }
]
};
{ name: 'curl', location: 'bower_components/curl/src/curl' },
{ name: 'wire', location: 'bower_components/wire', main: 'wire' },
{ name: 'when', location: 'bower_components/when', main: 'when' },
{ name: 'meld', location: 'bower_components/meld', main: 'meld' },
{ name: 'cola', location: 'bower_components/cola', main: 'cola' },
{ name: 'poly', location: 'bower_components/poly', main: 'poly' }
],
preloads: ['poly/string', 'poly/array'],
// Turn off i18n locale sniffing. Change or remove this line if you want to
// test specific locales or try automatic locale-sniffing.
locale: false
});

curl(config, ['poly/string', 'poly/array']).next(['wire!main']);
})(curl);
4 changes: 2 additions & 2 deletions labs/architecture-examples/cujo/bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "todomvc-cujo",
"name": "todomvc-cujoJS",
"version": "0.0.0",
"dependencies": {
"todomvc-common": "~0.1.4",
"curl": "~0.7.3",
"cola": "latest",
"poly": "~0.5.1",
"when": "~2.0.1",
"when": "~2.1.0",
"wire": "~0.9.4",
"meld": "~1.3.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
node_modules
/test/curl
test/util
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "test/curl"]
path = test/curl
url = https://unscriptable@github.com/cujojs/curl.git
[submodule "test/util"]
path = test/util
url = https://unscriptable@github.com/cujojs/util.git
[submodule "support/when"]
path = support/when
url = https://github.com/cujojs/when.git
110 changes: 110 additions & 0 deletions labs/architecture-examples/cujo/bower_components/cola/Collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Collection
*/
(function(define) {
define(function(require) {

var Base, resolver, eventTypes, simpleStrategy;

Base = require('./hub/Base');
resolver = require('./collectionAdapterResolver');
simpleStrategy = require('./network/strategy/default');

eventTypes = extend(Base.prototype.eventTypes, {
// collection item events. most of these come with data. devs can
// decide to use these events for their own purposes or send
// different data than described here, the following list outlines
// the intended behavior.
add: 1, // data == item added
remove: 1, // data == item removed
target: 1, // data == item targeted TODO: rename this to "point"?
// multi-item events
select: 1, // select an item (data == item)
unselect: 1, // deselect an item (data == item)
// batch events
collect: 1, // start of batch mode (until abort or submit) (data = batch purpose)
deliver: 1 // collected items (data = batch purpose with collected items array as property)
});

function Collection(options) {
Base.call(this, options);

if(!options) {
options = {};
}

this.strategy = options.strategy;
if (!this.strategy) this.strategy = simpleStrategy(options.strategyOptions);

}

Collection.prototype = Object.create(Base.prototype, {

eventTypes: { value: eventTypes },

resolver: { value: resolver },

forEach: {
value: function forEach(lambda) {
var provider = this.getProvider();
return provider && provider.forEach(lambda);
}
},

findItem: {
value: function (anything) {
var info = this._findItemFor(anything);
return info && info.item;
}
},

findNode: {
value: function (anything) {
var info = this._findNodeFor(anything);
return info && info.node;
}
},

getProvider: {
value: function () {
var a, i = this.adapters.length;
while(a = this.adapters[--i]) {
if(a.provide) return a;
}
}
},

_findNodeFor: {
value: function (anything) {
var node, i, adapters, adapter;

adapters = this.adapters;

// loop through adapters that have the findNode() method
// to try to find out which adapter and which node
i = 0;
while (!node && (adapter = adapters[i++])) {
if (adapter.findNode) {
node = adapter.findNode(anything);
}
}

return node && { node: node };
}
}

});

return Collection;

function extend(base, mixin) {
var extended = Object.create(base);
for(var p in mixin) {
extended[p] = mixin[p];
}

return extended;
}

});
}(typeof define === 'function' ? define : function(factory) { module.exports = factory(require); }));
Loading