Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created June 30, 2010 22:13

Revisions

  1. lsmith revised this gist Jul 1, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,7 @@ Y.Plugin.NodeIO = Y.Base.create('node-io', Y.Plugin.Base, [], {
    placement : {
    value : 'replace',
    validator : function(val){
    return /replace|(?:ap|pre)pend/.test(val);
    return /^(?:replace|(?:ap|pre)pend)$/.test(val);
    }
    },

  2. lsmith renamed this gist Jul 1, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. lsmith revised this gist Jul 1, 2010. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -71,4 +71,7 @@ Y.Plugin.NodeIO = Y.Base.create('node-io', Y.Plugin.Base, [], {
    validator: Y.Lang.isObject
    }
    }
    });
    });

    // Sugar coated alias
    Y.Plugin.NodeIO.prototype.refresh = Y.Plugin.NodeIO.prototype.load;
  4. lsmith created this gist Jun 30, 2010.
    74 changes: 74 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    Y.Plugin.NodeIO = Y.Base.create('node-io', Y.Plugin.Base, [], {
    _inProgress: null,
    _ioHandlers: null,

    initializer: function () {
    this.publish("success", { defaultFn: this._defSuccessFn });

    this.after('uriChange', this._afterUriChange);

    this._ioHandlers = {
    success: Y.bind(this._handleResponse, this, "success"),
    failure: Y.bind(this._handleResponse, this, "failure"),
    timeout: Y.bind(this._handleResponse, this, "timeout")
    };
    },

    load : function(uri) {
    var config = this.get("ioConfig");

    uri || (uri = this.get('uri'));
    this.set('uri', uri);

    config.on = this._ioHandlers;

    this._inProgress = Y.io(this.get('uri'), ioConfig);

    return this;
    },

    abort : function() {
    this._stopIO();

    return this;
    },

    _stopIO : function() {
    if (this._inProgress) {
    this._inProgress.abort();
    this._inProgress = null;
    }
    },

    _handleResponse: function (id, o, type) {
    this.fire(type, { id: id, response: o });
    this._inProgress = null;
    },

    _defSuccessFn : function(e) {
    this.get('host').insert(e.responseText, this.get('placement'));
    },

    _afterUriChange: function () {
    this._stopIO();
    }
    }, {
    NS : 'io',
    ATTRS : {
    uri : {
    validator: Y.Lang.isString
    },

    placement : {
    value : 'replace',
    validator : function(val){
    return /replace|(?:ap|pre)pend/.test(val);
    }
    },

    ioConfig : {
    value: {},
    validator: Y.Lang.isObject
    }
    }
    });