Skip to content

Commit

Permalink
gallery-2010.11.03-19-46 ghinch gallery-datasource-manage-stale
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed Nov 3, 2010
1 parent acc3dbd commit b6089b5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/gallery-datasource-manage-stale/build.properties
@@ -0,0 +1,23 @@
# MyComponent Build Properties

# As long as the 'builder' project is cloned to the default folder
# next to the 'yui3' project folder, the 'builddir' property does not
# need to be changed
#
# If the 'builder' project is checked out to an alternate location, this
# property should be updated to point to the checkout location.
builddir=../../../builder/componentbuild

# The name of the component. E.g. event, attribute, widget
component=gallery-datasource-manage-stale

# The list of files which should be concatenated to create the component.
# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
component.jsfiles=manage-stale.js

# The list of modules this component requires. Used to setup the Y.add module call for YUI 3.
# NOTE: For a css component, this property is not used/required.

# component.use, component.supersedes, component.optional and component.skinnable are other properties which can be defined
component.requires=datasource-local
component.builddir=../../tmp
9 changes: 9 additions & 0 deletions src/gallery-datasource-manage-stale/build.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- YUI 3 Component Build File -->

<project name="DataSourceManageStale" default="local">
<description>Gallery DataSource Manage Stale Build File</description>
<property file="build.properties" />
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
</project>
55 changes: 55 additions & 0 deletions src/gallery-datasource-manage-stale/js/manage-stale.js
@@ -0,0 +1,55 @@
var IGNORE_STALE_RESPONSES = 'ignoreStaleResponses',
CANCEL_STALE_REQUESTS = 'cancelStaleRequests',
DATA = 'data',
HOST = 'host',
DEF_REQUEST_FN = '_defRequestFn';

Y.namespace('Plugin').DataSourceManageStale = Y.Base.create('datasource-manage-stale', Y.Plugin.Base, [], {
_lastId : null,
_transactions : null,

_doBeforeData : function (e) {
if (!this._transactions[e.tId] || (this.get(IGNORE_STALE_RESPONSES) && e.tId != this._lastId)) {
e.halt();
}
},

_doBeforeDefRequestFn : function (e) {
if (this.get(CANCEL_STALE_REQUESTS)) {
Y.Object.each(this._transactions, function (t, id) {
if (t.abort) {
t.abort();
delete this._transactions[id];
delete Y.DataSource.Local.transactions[id];
}
}, this);
}
},

_doAfterDefRequestFn : function (e) {
if (this.get(IGNORE_STALE_RESPONSES)) {
this._lastId = e.tId;
}

this._transactions[e.tId] = Y.DataSource.Local.transactions[e.tId];
},

initializer : function () {
this._transactions = {};

this.doBefore(DATA, this._doBeforeData, this);
this.doBefore(DEF_REQUEST_FN, this._doBeforeDefRequestFn, this);
this.doAfter(DEF_REQUEST_FN, this._doAfterDefRequestFn, this);
}
}, {
NS : 'stale',

ATTRS : {
cancelStaleRequests : {
value : false
},
ignoreStaleResponses : {
value : false
}
}
});

0 comments on commit b6089b5

Please sign in to comment.