Skip to content

Commit

Permalink
Add build files for anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahmanor committed Sep 25, 2012
1 parent 83e8bf1 commit f1a2814
Show file tree
Hide file tree
Showing 12 changed files with 1,662 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
.anvil
17 changes: 17 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"source": "src",
"spec": "test",
"output": {
"full": "lib",
"partial": {
"../vsdoc/amplify-vsdoc.js": "./lib"
}
},
"anvil.jshint": {
"all": true
},
"anvil.uglify" : {
"all": true
},
"dependencies": [ "anvil.jshint", "anvil.uglify" ]
}
6 changes: 6 additions & 0 deletions concat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"./amplify.js": [ "./amplify.core.js", "./amplify.request.js", "./amplify.store.js" ],
"./amplify.core.js": [ "./amplify.core.js" ],
"./amplify.request.js": [ "./amplify.request.js" ],
"./amplify.store.js": [ "./amplify.store.js" ]
}
10 changes: 10 additions & 0 deletions header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
{{{name}}} - {{{description}}}
version: {{{version}}}
author: {{{author}}}
copyright: 2011 - 2012
license: Dual licensed (http://appendto.com/open-source-licenses)
MIT (http://www.opensource.org/licenses/mit-license)
GPL (http://www.opensource.org/licenses/gpl-license)
website: http://amplifyjs.com
*/
115 changes: 115 additions & 0 deletions lib/amplify.core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
amplify - AmplifyJS is a set of components for data management and application communication.
version: 1.1.0
author: appendTo (http://appendto.com/)
copyright: 2011 - 2012
license: Dual licensed (http://appendto.com/open-source-licenses)
MIT (http://www.opensource.org/licenses/mit-license)
GPL (http://www.opensource.org/licenses/gpl-license)
website: http://amplifyjs.com
*/
(function( global, undefined ) {

var slice = [].slice,
subscriptions = {};

var amplify = global.amplify = {
publish: function( topic ) {
if ( typeof topic !== "string" ) {
throw new Error( "You must provide a valid topic to publish." );
}

var args = slice.call( arguments, 1 ),
topicSubscriptions,
subscription,
length,
i = 0,
ret;

if ( !subscriptions[ topic ] ) {
return true;
}

topicSubscriptions = subscriptions[ topic ].slice();
for ( length = topicSubscriptions.length; i < length; i++ ) {
subscription = topicSubscriptions[ i ];
ret = subscription.callback.apply( subscription.context, args );
if ( ret === false ) {
break;
}
}
return ret !== false;
},

subscribe: function( topic, context, callback, priority ) {
if ( typeof topic !== "string" ) {
throw new Error( "You must provide a valid topic to create a subscription." );
}

if ( arguments.length === 3 && typeof callback === "number" ) {
priority = callback;
callback = context;
context = null;
}
if ( arguments.length === 2 ) {
callback = context;
context = null;
}
priority = priority || 10;

var topicIndex = 0,
topics = topic.split( /\s/ ),
topicLength = topics.length,
added;
for ( ; topicIndex < topicLength; topicIndex++ ) {
topic = topics[ topicIndex ];
added = false;
if ( !subscriptions[ topic ] ) {
subscriptions[ topic ] = [];
}

var i = subscriptions[ topic ].length - 1,
subscriptionInfo = {
callback: callback,
context: context,
priority: priority
};

for ( ; i >= 0; i-- ) {
if ( subscriptions[ topic ][ i ].priority <= priority ) {
subscriptions[ topic ].splice( i + 1, 0, subscriptionInfo );
added = true;
break;
}
}

if ( !added ) {
subscriptions[ topic ].unshift( subscriptionInfo );
}
}

return callback;
},

unsubscribe: function( topic, callback ) {
if ( typeof topic !== "string" ) {
throw new Error( "You must provide a valid topic to remove a subscription." );
}

if ( !subscriptions[ topic ] ) {
return;
}

var length = subscriptions[ topic ].length,
i = 0;

for ( ; i < length; i++ ) {
if ( subscriptions[ topic ][ i ].callback === callback ) {
subscriptions[ topic ].splice( i, 1 );
break;
}
}
}
};

}( this ) );
11 changes: 11 additions & 0 deletions lib/amplify.core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1a2814

Please sign in to comment.