Browse files

started to get the real time stuff a bit more automated

  • Loading branch information...
1 parent b01a600 commit 1522a2bff4e88187d0f84dad12e5a8a83cede4a4 Techwraith committed Oct 24, 2012
View
2 Jakefile
@@ -27,7 +27,7 @@ namespace('doc', function () {
});
-desc('Generate the geddy core.js file');
+desc('Generate the geddy core files');
task('buildjs', function(){
var cmd = 'browserify templates/build/build.js' +
' -o templates/base/public/js/core/core.js -i ./logger'
View
2 lib/app.js
@@ -241,8 +241,6 @@ var App = function () {
// add event listeners to all the models
// set up socket.io emitters for each event
- console.log(geddy.model.descriptionRegistry);
-
var events = [
, 'save'
, 'update'
View
28 templates/base/public/js/config/init.js
@@ -0,0 +1,28 @@
+// Use this file to do all of your initial setup - this will be run after
+// core/core.js and all of your models.
+
+/*
+ * to set up realtime for your specific models
+ * pass an array of model names into the method
+ * below: */
+
+// geddy.io.addListenersForModels();
+
+/*
+ * example:
+ *
+ * geddy.io.addListenersForModels(['Item']);
+ *
+ * geddy.model.Item.on('save', function (item) {
+ * console.log(item);
+ * });
+ *
+ * geddy.model.Item.on('update', function (item) {
+ * console.log(item);
+ * });
+ *
+ * geddy.model.Item.on('remove', function (item) {
+ * console.log(item);
+ * });
+ *
+ */
View
35 templates/base/public/js/core/core.js
@@ -1039,11 +1039,13 @@ utils.mixin(model, new (function () {
// contains an Object literal keyed by field name, and the
// error message for the first failed validation for that
// property
+ // Use raw, invalid value on the instance
if (validated.err) {
errs = errs || {};
errs[p] = validated.err;
+ item[p] = params[p];
}
- // Otherwise add this property to the return item
+ // Otherwise add the type-coerced, valid value to the return item
else {
item[p] = validated.val;
}
@@ -12636,15 +12638,40 @@ var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="Sho
require.define("/templates/build/build.js",function(require,module,exports,__dirname,__filename,process,global){window.geddy = {}
// require model
-window.geddy.model = require('model');
+geddy.model = require('model');
// mix utilities into geddy
var utilities = require('utilities');
utilities.mixin(geddy, utilities);
// require socket.io-client
-window.geddy.io = require('socket.io-client');
-window.geddy.socket = window.geddy.io.connect('http://localhost');
+geddy.io = require('socket.io-client');
+geddy.socket = geddy.io.connect('http://localhost');
+
+geddy.io.listenForModelEvents = function (model) {
+ var events = [
+ 'save'
+ , 'update'
+ , 'remove'
+ ];
+
+ for (var e in events) {
+ geddy.socket.on(model.modelName + ':' + events[e], function (data) {
+ (function (event) {
+ model.emit(event, data);
+ })(events[e]);
+ });
+ };
+}
+
+geddy.io.addListenersForModels = function (models) {
+ for (var i in models) {
+ (function (model) {
+ geddy.io.listenForModelEvents(model);
+ })(geddy.model[models[i]]);
+ }
+}
+
});
require("/templates/build/build.js");
View
7 templates/base/views/ejs/layouts/application.html.ejs
@@ -15,6 +15,9 @@
<%- scriptLink('/js/jquery.min.js', {type:'text/javascript'}) %>
<%- scriptLink('/js/bootstrap.min.js', {type:'text/javascript'}) %>
+ <%- scriptLink('/js/core/core.js', {type: 'text/javascript'}) %>
+ <%- scriptLink('/js/core/models.js', {type: 'text/javascript'}) %>
+ <%- scriptLink('/js/config/init.js', {type: 'text/javascript'}) %>
<%- styleLink('/css/bootstrap.min.css', {rel:'stylesheet'}) %>
<%- styleLink('/css/style.css', {rel:'stylesheet'}) %>
@@ -37,8 +40,8 @@
<div class="nav-collapse">
<ul class="nav">
<li class="active"><%- linkTo('Home', '/') %></li>
- <li><%- linkTo('Tutorial', 'http://geddyjs.org/tutorial.html') %></li>
- <!--<li><%- linkTo('Docs', 'http://geddyjs.org/docs.html') %></li>-->
+ <li><%- linkTo('Tutorial', 'http://geddyjs.org/tutorial') %></li>
+ <%- linkTo('Docs', 'http://geddyjs.org/documentation') %></li>
</ul>
</div><!--/.nav-collapse -->
</div>
View
29 templates/build/build.js
@@ -1,18 +1,37 @@
window.geddy = {}
// require model
-window.geddy.model = require('model');
+geddy.model = require('model');
// mix utilities into geddy
var utilities = require('utilities');
utilities.mixin(geddy, utilities);
// require socket.io-client
-window.geddy.io = require('socket.io-client');
-window.geddy.socket = window.geddy.io.connect('http://localhost');
+geddy.io = require('socket.io-client');
+geddy.socket = geddy.io.connect('http://localhost');
-window.geddy.model.startListening = function (models) {
+geddy.io.listenForModelEvents = function (model) {
+ var events = [
+ 'save'
+ , 'update'
+ , 'remove'
+ ];
+
+ for (var e in events) {
+ geddy.socket.on(model.modelName + ':' + events[e], function (data) {
+ (function (event) {
+ model.emit(event, data);
+ })(events[e]);
+ });
+ };
+}
+
+geddy.io.addListenersForModels = function (models) {
for (var i in models) {
- // start here
+ (function (model) {
+ geddy.io.listenForModelEvents(model);
+ })(geddy.model[models[i]]);
}
}
+

0 comments on commit 1522a2b

Please sign in to comment.