Git Product home page Git Product logo

capsule's People

Contributors

faulkner avatar henrikjoreteg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

capsule's Issues

ID generation on the client side

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?

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.

Update/Maintenance?

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?

sockets

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,

demo

please add a wroking demo. pages and pages of documentation with no demo is not very helpful.

overriding fetch()

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?

Would you recommend using Capsule client-side only?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.