henrikjoreteg / capsule Goto Github PK
View Code? Open in Web Editor NEWRealtime web app framework for Backbone, socket.io and node.js
License: MIT License
Realtime web app framework for Backbone, socket.io and node.js
License: MIT License
when a model is create don the client side, the no id is assigned to it. hence, since he server cannot detect the model, calling setServer() on a model created on the client side is not effective.
Could I use Capsule to deflate a view to JSON send it somewhere via websockets and then inflate the view again?
We have an experimental application and one of its goals is to use only websockets after the initial payload. In one case we want to do something where a user could be accessing 1 of 500 different interactive widgets. We're using Capsule to dynamically pass a model for each when needed and we want to do something similar with views.
Possible? Thanks for any feedback.
I'd love to use something like this, but the last few updates seem to have been made in June of last year. Has this module been left out to dry? Have its components been moved on to something else?
Wonder if the following could help solve undefined
socket:
diff -Naur capsule.orig/capsule.js capsule/capsule.js
--- capsule.orig/capsule.js 2011-05-25 01:03:35.000000000 -0400
+++ capsule/capsule.js 2011-05-25 01:02:34.000000000 -0400
@@ -13,7 +13,17 @@
if (typeof exports !== 'undefined') {
Backbone = require('backbone');
_ = require('underscore')._;
- uuid = require('node-uuid');
+ try {
+ uuid = require('node-uuid');
+ } catch(err) {
+ // simpler nonce generator
+ uuid = function() {
+ function rnd() {
+ return Math.floor(Math.random() * 1e9).toString(36);
+ }
+ return (Date.now() & 0x7fff).toString(36) + rnd() + rnd() + rnd();
+ };
+ }
Capsule = exports;
server = true;
} else {
@@ -72,6 +82,15 @@
this[label].parent = this;
},
+ // ###send
+ // Sends JS object to the remote side.
+ // N.B. you have to set topmost model's socket property
+ send: function(obj) {
+ // get the socket
+ for (var root = this; root.parent; root = root.parent) ;
+ root.socket && root.socket.send(obj);
+ },
+
// ###modelGetter
// Convenience method for retrieving any model, no matter where, by id.
modelGetter: function (id) {
@@ -125,7 +144,7 @@
// ###deleteServer
// Sends delete event for `id` to server.
deleteServer: function () {
- socket.send({
+ this.send({
event: 'delete',
id: this.id
});
@@ -134,7 +153,7 @@
// ###callServerMethod
// Send a method call event. To trigger a model method on the server (if allowed).
callServerMethod: function (method) {
- socket.send({
+ this.send({
event: 'method',
id: this.id,
method: method
@@ -312,7 +331,7 @@
// ###setServer
// Our server version of the normal `set` method. Takes a hash of attributes
setServer: function(attrs) {
- socket.send({
+ this.send({
event: 'set',
id: this.id,
change: attrs
@@ -322,7 +341,7 @@
// ###unsetServer
// Unsets a given property
unsetServer: function(property) {
- socket.send({
+ this.send({
event: 'unset',
id: this.id,
property: property
@@ -355,6 +374,15 @@
if (this.id && !Capsule.models[this.id]) Capsule.models[this.id] = this;
},
+ // ###send
+ // Sends JS object to the remote side.
+ // N.B. you have to set topmost model's socket property
+ send: function(obj) {
+ // get the socket
+ for (var root = this; root.parent; root = root.parent) ;
+ root.socket && root.socket.send(obj);
+ },
+
// ###safeAdd
// Is used to add items to the collection from an untrusted source (the client)
// it inits the collection's model type. Sets the supplied properties on that new
@@ -373,7 +401,7 @@
// ###addServer
// The server version of backbone's `add` method.
addServer: function (data) {
- socket.send({
+ this.send({
event: 'add',
id: this.id,
data: data
@@ -383,7 +411,7 @@
// ###moveServer
// Send the `move` event
moveServer: function (id, newPosition) {
- socket.send({
+ this.send({
event: 'move',
collection: this.id,
id: id,
please add a wroking demo. pages and pages of documentation with no demo is not very helpful.
calling Capsule.model.fetch() leads to an error like this:
A 'url' property or function must be specified
should it be overridden to be more integrated with socket.io, or should this method be removed?
https://github.com/andyet/Capsule/blob/master/capsule.models.js#L204
You've cut-pasted a section of docco without updating the function name. I didn't think this was worth a fork + pull request!
I'd like to use Capsule a little differently then it was designed. Could I keep the collapsed model state in mongo on the server and interact with the raw data without creating backbone models?
The goal would be to use it for syncing (collapsing/rebuilding) sub-models across different clients. The server will be acting more like a pneumatic tube routing the capsule to the clients that need it yet still maintaing the ability to alter the data using its own methods unrelated to backbone.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.