Skip to content
Open
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
9 changes: 5 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
</div>
</nav>



<div class="container">

<footer>
<p>&copy; Consensus</p>
</footer>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>

Expand All @@ -66,6 +66,7 @@
<script src="js/cuore/Cuore.Page.js"></script>
<script src="js/cuore/Cuore.Registry.js"></script>
<script src="js/cuore/Cuore.Directory.js"></script>
<script src="js/cuore/StatePersisters/Cuore.LocalStorageStatePersister.js"></script>
<script src="js/cuore/Cuore.State.js"></script>
<script src="js/cuore/Cuore.Component.js"></script>
<script src="js/cuore/Cuore.HandlerSet.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions js/cuore/Cuore.Page.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CUORE.Page = CUORE.Class(null, {

init: function() {
init: function(statePersister) {
this.components = new CUORE.Registry();
this.services = new CUORE.Directory();
this.state = new CUORE.State();
this.state = new CUORE.State(statePersister);
this.setUp();
},

Expand Down
72 changes: 44 additions & 28 deletions js/cuore/Cuore.State.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
CUORE.State = CUORE.Class(null, {

keys: undefined,
map: undefined,
statePersister: undefined,

init: function() {
this.keys = [];
this.map = {};
init: function(statePersister) {
this._initialize_in_page();
this.statePersister = statePersister || CUORE.NullStatePersister();
},

hasKey: function(key) {
return this.keys.indexOf(key) != -1;
},

save: function(key, value) {
if (key === undefined) {
return;
}

if (this._should_be_deleted(value)) {
this.delete(key);
return;
}

this._save_in_page(key, value);
this._persist(key, value);
},

delete: function(key) {
this._removeKey(key);
this.statePersister.remove(key);
},

retrieve: function(key) {
if (!this.hasKey(key)) {
this._save_in_page(
key,
this.statePersister.retrieve(key)
);
}
return this.map[key];
},

clear: function() {
this._initialize_in_page();
},

_addKey: function(key) {
if (this.hasKey(key)) return;
this.keys.push(key);
Expand All @@ -21,38 +54,21 @@ CUORE.State = CUORE.Class(null, {
this.keys.splice(this.keys.indexOf(key), 1);
},

save: function(key, value) {
if (key === undefined) return;
if (value === undefined) return;
this._save_in_page(key,value);
this._save_local(key,value);
},

_save_in_page: function(key, value) {
this._addKey(key);
this.map[key] = value;
},

_save_local: function(key,value){
window.localStorage.setItem(key,value);
},


_from_local: function(key){
var fromLocal = window.localStorage.getItem(key);
if (fromLocal != undefined){
this._save_in_page(key,fromLocal);
}
return fromLocal;
_persist: function(key, value) {
this.statePersister.save(key, value);
},

delete: function(key) {
this._removeKey(key);
_should_be_deleted: function(value) {
return value === undefined || value === null;
},

retrieve: function(key) {
if (!this.hasKey(key)) return this._from_local(key);
return this.map[key];
_initialize_in_page: function() {
this.keys = [];
this.map = {};
}

});
20 changes: 20 additions & 0 deletions js/cuore/StatePersisters/Cuore.LocalStorageStatePersister.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

CUORE.LocalStorageStatePersister = (function() {
return function() {
return {
save: function(key, value) {
window.localStorage.setItem(key, value);
},

retrieve: function(key) {
return window.localStorage.getItem(key);

},

remove: function(key) {
window.localStorage.removeItem(key);
}
};
};
})();
17 changes: 17 additions & 0 deletions js/cuore/StatePersisters/Cuore.NullStatePersister.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

CUORE.NullStatePersister = (function() {
return function() {
return {
save: function(key, value) {

},
retrieve: function(key) {

},
remove: function(key) {

}
};
};
})();
8 changes: 4 additions & 4 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
CUORE.Dom.ready(function() {
var currentLocale = (navigator.language || navigator.browserLanguage);
var currentLocale = (navigator.language || navigator.browserLanguage);

document.labels = {};
document.labels[currentLocale] = {
"a.key": "a literal",
};

CUORE.Bus.enableDebug();

document.page = new FirstTime();
document.page = new FirstTime(CUORE.LocalStorageStatePersister());

document.page.draw();
});
42 changes: 21 additions & 21 deletions js/names.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
FIRST_NAMES = [
'Alligator','Bat','Bear','Bison','Bobcat','Butterfly','Caribou','Cat',
'Condor','Crab','Crocodile','Deer','Dog','Dolphin','Elephant','Falcon','Ferret',
'Fisher','Fox','Frog','Goat','Hummingbird','Kangaroo','Koala','Leopard','Lion',
'Lynx','Manatee','Ocelot','','Otter','Owl','Panther','Parrot','Pelican','Penguin',
'Puma','Rabbit','Shark','Sheep','Snake','Spider','Squirrel','Terrapin','Tiger','Turtle',
'Walrus','Warbler','Whale','Wolf'
];
var FIRST_NAMES = [
'Alligator', 'Bat', 'Bear', 'Bison', 'Bobcat', 'Butterfly', 'Caribou', 'Cat',
'Condor', 'Crab', 'Crocodile', 'Deer', 'Dog', 'Dolphin', 'Elephant', 'Falcon', 'Ferret',
'Fisher', 'Fox', 'Frog', 'Goat', 'Hummingbird', 'Kangaroo', 'Koala', 'Leopard', 'Lion',
'Lynx', 'Manatee', 'Ocelot', '', 'Otter', 'Owl', 'Panther', 'Parrot', 'Pelican', 'Penguin',
'Puma', 'Rabbit', 'Shark', 'Sheep', 'Snake', 'Spider', 'Squirrel', 'Terrapin', 'Tiger', 'Turtle',
'Walrus', 'Warbler', 'Whale', 'Wolf'
],

MIDDLE_NAMES = [
'Acrion','Aedesia','Aenesidemus','Aesara','Brontinus','Callicles','Calliphon','Callistratus',
'Carneades','Damascius','Democrates','Demonax','Echecrates','Empedocles','Epicurus',
'Eubulides','Favorinus','Geminus','Gorgias','Hegias','Heraclitus','Hypatia','Leucippus','Maximus',
'Menedemus','Monimus','Nicomachus','Onasander','Onatas','Panaetius','Panthoides','Phaedrus',
'Philiscus','Phintys','Plotinus','Polus','Sallustius','Siro','Sosipatra','Stilpo','Syrianus','Telauges',
'Theano','Themistius','Timycha','Xeniades','Xenocrates','Zenobius','Zenodotus'
];
'Acrion', 'Aedesia', 'Aenesidemus', 'Aesara', 'Brontinus', 'Callicles', 'Calliphon', 'Callistratus',
'Carneades', 'Damascius', 'Democrates', 'Demonax', 'Echecrates', 'Empedocles', 'Epicurus',
'Eubulides', 'Favorinus', 'Geminus', 'Gorgias', 'Hegias', 'Heraclitus', 'Hypatia', 'Leucippus', 'Maximus',
'Menedemus', 'Monimus', 'Nicomachus', 'Onasander', 'Onatas', 'Panaetius', 'Panthoides', 'Phaedrus',
'Philiscus', 'Phintys', 'Plotinus', 'Polus', 'Sallustius', 'Siro', 'Sosipatra', 'Stilpo', 'Syrianus', 'Telauges',
'Theano', 'Themistius', 'Timycha', 'Xeniades', 'Xenocrates', 'Zenobius', 'Zenodotus'
],

LAST_NAMES = [
'Armand','Bayer','Beccari','Berdyaev','Bontemps','Bové','Brophy','Camus','Caplan','Carter',
'Comfort','Day','Ellul','Fimmen','Franklin','Freinet','Goodman','Hennacy','Hiratsuka','Hiratsuka',
'Igualada','Kelly','Keyes','Khein','Landauer','Lecoin','Light','McCarthy','Montelius','Moreau','Moura',
'Nieuwenhuis','Ostergaard','Pankhurst','Philips','Poch','Rankin','Relgis','Ryner','Saulière','Selenka',
'Starhawk','Stewart','Tolstoy','Vonnegut','Westerweel','Willcox','Wolfe','Woodcock'
];
'Armand', 'Bayer', 'Beccari', 'Berdyaev', 'Bontemps', 'Bové', 'Brophy', 'Camus', 'Caplan', 'Carter',
'Comfort', 'Day', 'Ellul', 'Fimmen', 'Franklin', 'Freinet', 'Goodman', 'Hennacy', 'Hiratsuka', 'Hiratsuka',
'Igualada', 'Kelly', 'Keyes', 'Khein', 'Landauer', 'Lecoin', 'Light', 'McCarthy', 'Montelius', 'Moreau', 'Moura',
'Nieuwenhuis', 'Ostergaard', 'Pankhurst', 'Philips', 'Poch', 'Rankin', 'Relgis', 'Ryner', 'Saulière', 'Selenka',
'Starhawk', 'Stewart', 'Tolstoy', 'Vonnegut', 'Westerweel', 'Willcox', 'Wolfe', 'Woodcock'
];
5 changes: 2 additions & 3 deletions js/pages/FirstTime.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var FirstTime = CUORE.Class(CUORE.Page, {

initializeServices: function() {
this.addService(new Names());
this.addService(new Names());
},

initializeComponents: function() {
this.addComponent(new Involved(),'involved');
this.addComponent(new Involved(), 'involved');
},

});
22 changes: 10 additions & 12 deletions js/services/Names.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Names = CUORE.Class(CUORE.Service, {

init: function() {
Names.parent.init.call(this);
this.name = 'NAMES';
Names.parent.init.call(this);
this.name = 'NAMES';
},


generate: function(params,eventName) {
generate: function(params, eventName) {
var SPACER = " ";
var name = this._pickRandom( FIRST_NAMES );
var middle = this._pickRandom( MIDDLE_NAMES );
var last = this._pickRandom( LAST_NAMES );
var name = this._pickRandom(FIRST_NAMES);
var middle = this._pickRandom(MIDDLE_NAMES);
var last = this._pickRandom(LAST_NAMES);
this.emit(eventName, name + SPACER + middle + SPACER + last);
},

Expand All @@ -22,12 +21,11 @@ Names = CUORE.Class(CUORE.Service, {
return response;
},

_getRandomInt:function (max) {
return Math.floor(Math.random() * (max + 1)) ;
_getRandomInt: function(max) {
return Math.floor(Math.random() * (max + 1));
},

_pickRandom:function (pool) {
return pool[this._getRandomInt(pool.length - 1)] ;
_pickRandom: function(pool) {
return pool[this._getRandomInt(pool.length - 1)];
},

});
25 changes: 24 additions & 1 deletion spec/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,40 @@
<script src="lib/jasmine-2.3.2/jasmine.js"></script>
<script src="lib/jasmine-2.3.2/jasmine-html.js"></script>
<script src="lib/jasmine-2.3.2/boot.js"></script>
<script src="lib/sinon-1.15.0.js" type="text/javascript"></script>

<!-- include source files here... -->
<script src="../js/cuore/Cuore.js"></script>
<script src="../js/cuore/Cuore.Class.js"></script>
<script src="../js/cuore/Cuore.Bus.js"></script>
<script src="../js/cuore/Cuore.Service.js"></script>
<script src="../js/cuore/Cuore.Dom.js"></script>
<script src="../js/cuore/Cuore.Page.js"></script>
<script src="../js/cuore/Cuore.Registry.js"></script>
<script src="../js/cuore/Cuore.Directory.js"></script>
<script src="../js/cuore/StatePersisters/Cuore.LocalStorageStatePersister.js"></script>
<script src="../js/cuore/Cuore.State.js"></script>
<script src="../js/cuore/Cuore.Message.js"></script>
<script src="../js/cuore/Cuore.Component.js"></script>
<script src="../js/cuore/Services/Cuore.Services.Label.js"></script>
<script src="../js/cuore/Services/Cuore.Services.Null.js"></script>
<script src="../js/cuore/StatePersisters/Cuore.NullStatePersister.js"></script>
<script src="../js/cuore/StatePersisters/Cuore.LocalStorageStatePersister.js"></script>
<script src="../js/names.js"></script>
<script src="../js/services/Names.js"></script>


<!-- include spec files here... -->
<script src="spec/Cuore.Bus.Spec.js"></script>
<script src="spec/Cuore.Mocks.js"></script>
<script src="spec/SpecHelper.js"></script>
<script src="spec/Cuore.Matchers.js"></script>
<script src="spec/Cuore.Bus.Spec.js"></script>
<script src="spec/Cuore.State.Spec.js"></script>
<script src="spec/Cuore.Core.Spec.js"></script>
<script src="spec/Cuore.Page.Spec.js"></script>
<script src="spec/Cuore.Registry.Spec.js"></script>
<script src="spec/Cuore.Directory.Spec.js"></script>
<script src="spec/Cuore.Message.Spec.js"></script>
<script src="spec/NameServiceSpec.js"></script>


Expand Down
Loading