Sha256: 6e151d043cf77db0966d61e18a08e9b9e861436c3d7745e06d20ac2b2bc6c4fb

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

if (JS.Proxy === undefined) JS.Proxy = {};

JS.Proxy.Virtual = new JS.Class('Proxy.Virtual', {
  initialize: function(klass) {
    var bridge     = function() {},
        proxy      = new JS.Class(),
        delegators = {},
        method, func;
    
    bridge.prototype = klass.prototype;
    
    for (method in klass.prototype) {
      func = klass.prototype[method];
      if (JS.isFn(func) && func !== klass) func = this.klass.forward(method);
      delegators[method] = func;
    }
    
    proxy.include({
      initialize: function() {
        var args    = arguments,
            subject = null;
        
        this.__getSubject__ = function() {
          subject = new bridge;
          klass.apply(subject, args);
          return (this.__getSubject__ = function() { return subject; })();
        };
      },
      klass: klass,
      constructor: klass
    }, false);
    
    proxy.include(new JS.Module(delegators), false);
    proxy.include(this.klass.InstanceMethods, true);
    return proxy;
  },
  
  extend: {
    forward: function(name) {
      return function() {
        var subject = this.__getSubject__();
        return subject[name].apply(subject, arguments);
      };
    },
    
    InstanceMethods: new JS.Module({
      extend: function(source) {
        this.__getSubject__().extend(source);
        var method, func;
        for (method in source) {
          func = source[method];
          if (JS.isFn(func)) func = JS.Proxy.Virtual.forward(method);
          this[method] = func;
        }
      }
    })
  }
});

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
spontaneous-0.1.0.alpha1 application/js/vendor/JS.Class-2.1.5/src/proxy.js
acts_as_dashboard-0.4.1 generators/dashboard/templates/js.class-2.1.4/src/proxy.js
acts_as_dashboard-0.4.0 generators/dashboard/templates/js.class-2.1.4/src/proxy.js
acts_as_dashboard-0.3.3 generators/dashboard/templates/js.class-2.1.4/src/proxy.js
acts_as_dashboard-0.3.2 generators/dashboard/templates/js.class-2.1.4/src/proxy.js
acts_as_dashboard-0.3.0 generators/dashboard/templates/js.class-2.1.4/src/proxy.js
acts_as_dashboard-0.1.0 generators/dashboard/templates/js.class-2.1.4/src/proxy.js