GithubHelp home page GithubHelp logo

amplify's People

Contributors

alexzeitler avatar arobson avatar awirick avatar dcneiner avatar duereg avatar elijahmanor avatar eliperelman avatar gijsk avatar jakerella avatar jcreamer898 avatar jdsharp avatar nicholascloud avatar redwolves avatar scottgonzalez avatar shellscape 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  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

amplify's Issues

Demos need to include json2.js

I am running IE 7.0.5730.13 running in a VMware image that Microsoft makes available for testing purposes and it fails everytime.

You can download the images at:
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en

(they are VPC image files but it is possible to make them into VMWare Images)

I am using this link to test in fiddle:
http://jsfiddle.net/gh/get/jquery/1.5/appendto/amplify/tree/master/store/demo/implicit/

I get this javascript error:
Line:204
Char:6
Error: 'JSON' is undefined

thanks,

Carlos

amplify.subscribe should allow you to subscribe to multiple messages in a single call.

I would like to be able to use the following code:

amplify.subscribe( "message.save message.update message.new", function () {
   // Do something whenever a message is saved, updated, or created
});

Right now, it would have to be written like this:

var callback = function () {
   // Do something whenever a message is saved, updated, or created
});

amplify.subscribe( "message.save", callback );
amplify.subscribe( "message.update", callback );
amplify.subscribe( "message.new", callback );

Add complete request callback

When a request is completed, a callback to a "complete" function should be made as well as the current publish "request.complete".

Why pub/sub when we already have jQuery.bind/triggerHandler?

Ever since jQuery officially supports wrapping non-DOM-elements, it essentially contains a generic pub/sub system:

$(anyobject).bind("dataexample", function(e, data) { alert(data.foo); });
...
$(anyobject).triggerHandler("dataexample", { foo: "bar" });

So why not just use that instead of the custom pub/sub implementation in core?

Promise interface support

amplify.request() should return jQuery.Deferred() object.

Example:

$.when(amplify.request("resource1"),
       amplify.request("resource2"))
 .then(function(data1, data2) {
           console.log("Resources are loaded!");
       },
       function() {
           console.log("Requests failed!");
       }
)```

Access sender/current request in decoder

I'd like to have access to the invoked request/resource in a decoder. As far as I can tell this is currently not supported, but should be easy to implement. Passing request, settings and ajaxSettings to decoder() probably.

Any chance for this happening?

Inconsistent expiration behaviour for memory storage when replacing

With*Storage and userData, if I replace a previously-expirable value and don't set an expiration, there is no expiration (which is the behavior I expect). With memory storage however, the first expiration will delete the replaced value (the setTimeout is not cleared).

amplify.store[type]( 'key', 'value1', {expires: 500} );
amplify.store[type]( 'key', 'value2' );
window.setTimeout( function(){ alert( amplify.store[type]( 'key' ) ) }, 1000 );

This JsFiddle tests all storage types available to the current browser.

Non-duplication of concurrent requests

When multiple concurrent requests occur, it would be valuable for amplify.js to reduce these requests to one ajax call.

For example, given:

amplify.request.define("X", "ajax", {
         url: "/x/{id}",
         dataType: "json",
         cache: true,
         type: "GET"
     });

amplify.request("X", { id: 1}, function () {});
amplify.request("X", { id: 1}, function () {});

Right now when I run this code (e.g. http://jsfiddle.net/Xg9gn/) two AJAX requests occur.

Obviously caching cannot occur until a request completes.

However, I believe a preferable model would be for the first request to block all future identical requests; those future requests would however subscribe to the results of the first request.

An option to force an AJAX request may be prudent (though I cannot think of a use case offhand).

Just a thought! :)

jsend decoder - throw an error when status is unknown

This is a simple change, which would be as follows:

amplify.request.decoders = {
  jsend: function( data, status, ampXHR, success, error ) {
        var handled = false; // ADDED
        if ( data.status === "success" ) {
            success( data.data );
            handled = true; // ADDED
        } else if ( data.status === "fail" ) {
            error( data.data, "fail" );
            handled = true; // ADDED
        } else if ( data.status === "error" ) {
            delete data.status;
            error( data, "error" );
            handled = true; // ADDED
        }
        if (!handled) {
            throw "JSON response does not conform to jsend spec";
        } // ADDED
    }
}

This can help track down nasty oversights, especially with spelling errors e.g. "suceess".

Caching broken for JSONP requests in jQuery

Because jQuery uses its own expando property to establish a unique global for the JSONP callback, amplify's caching mechanism is broken. It works again if you override using jQuery's jsonpCallback property. Perhaps a warning or amplify should explicitly set its own jsonpCallback?

Better documentation

I was originally going to say "better documentation for timeout / cache parameters", but I really feel like this is a product-wide issue.

Going to the "Store" method's documentation (http://amplifyjs.com/api/store/), the entry for "expires" is

expires: Duration in milliseconds that the value should be cached

That's it!

Missing information:

  1. What happens when it's undefined/null?
  2. What is the maximum value?
  3. What happens when it's negative?

There also seems to be no information on how to clear the entire cache or what happens when you do explicit storage usage and the browser doesn't support it.

I know there are forums where this information may be found, but someone should be updating the documentation with this information so we don't have the "needle in the haystack" approach to finding documentation (searching through forum posts)

addBehavior throws an exception in IE6 SP2

This line, in the block to support IE 5+, throws an exception

if ( div.addBehavior ) {
div.addBehavior( "#default#userdata" ); //throws "unspecified error" in IE6 SP2

I've verified this on several of our QA lab boxes with IE6 SP2. The versions affected (so far): 6.0.3790.3959 SP2

Expose amplify in AMD format

Now that jQuery is exposing itself w/ define, I feel like this will catch on more.

The easiest implementation would be:

define('amplify', function()
{
return amplify;
});

But the most correct would be to not use a global variable at all if an AMD loader exists on the page (underscore.js does a good job of this, I believe).

This allows amplify to be loaded using RequireJS or equivalent.

Throw an exception when data returned to does not conform to jsend

When I make an amplify.js request, and the response does not conform to the jsend spec, it would be nice if amplify.js threw an exception (or could be run in "strict" mode where it would throw an exception).

This would help a little bit with debugging, since at the moment it seems that when an amplify.js request does not conform to the jsend spec neither the success nor error handler are called - the response is silently ignored. Explicit failure is preferable.

Thanks!

amplify.store('key') always return null when navigate Back from another page

Here's a testcase: http://jsbin.com/3/oxexoc

On initial page load, everything works fine until you click on a web page (on another domain) then navigate Back. The localStorage reference in amplify.store code seems lost and returns a zero length, which probably explains why amplify.store('key') is always returning null. If you try to access directly to the localStorage instance, the key is actually there.

This bug is replicable on Safari 5.1.2 (7534.52.7) on Windows and Mobile Safari (7534.48.3) on iOS5 (iPhone).

IE9 issue - amplify is undefined

I was on page: http://amplifyjs.com/api/store/ and tried to run the fiddler sample and i get the following error message(s).

Screenshot: http://screencast.com/t/qRK5dkk28Lo

Console output:

SEC7112: Script from https://raw.github.com/appendto/amplify/master/core/amplify.core.js was blocked due to mime type mismatch
light
SEC7112: Script from https://raw.github.com/appendto/amplify/master/store/amplify.store.js was blocked due to mime type mismatch
light
SCRIPT5009: 'amplify' is undefined
light, line 34 character 5

Regex error in amplify.store.js

At line 201 in amplify.store.js, the regex used to sanitize the key is incorrect.

Unicode character \u37f is incorrect an should be corrected as \u037f

key = key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );

should be
key = key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );

This regex cause some parsing errors, such in IDE Visual Studio or with bundling feature in ASP.NET MVC4.

';' missing in minified version

The min version of amplified must have ';' at the end of the script.
i.e. (function(a,b){......}(amplify,jQuery);

While combining multiple js files, error is raised in subsequent script module.

I suggest to modify the build to add colon at the end as well as at the start of the script. At the start of the script will help reduce any other script's similar issue.

AJAX request success callback returns nested object

Hi,

I could be doing something ridiculously dumb, but I am trying to use amplify.request() to retrieve a user's github repos. Every example I read, the "data" parameter of the success callback is what it should be: the JSON deserialized into an object. However when I try and do this, the data parameter is actually an object with two properties, data.meta and data.data, with the data.data containing what I actually want.

Am I doing something wrong? Below is my source code.

$(function(){
    amplify.request.define("github-repos", "ajax", {
        url: "https://api.github.com/users/cocoahero/repos",
        dataType: "jsonp",
        type: "GET"
    });

    amplify.request("github-repos", function(data) {
        var html = "";
        $.each(data.data, function(i, repo) {
            html += "<h2>" + repo.name + "</h2>" + "<p>" + repo.description + "</p>";
        });
        $("#repos").html(html);
    });
});

Thanks!

Unsubscribe from topic during publish() callback

Hi,

If I try and unsubscribe my callback during the callback itself I get
the following error (in Firefox 6 - but I think browser is
irrelevant):

subscription is undefined
[Break On This Error] ret =
subscription.callback.apply( subscription.context, args );

amplify.js (line 38)

which is the 3rd line in this snippet:

for ( length = subscriptions[ topic ].length; i < length; i++ ) {
subscription = subscriptions[ topic ][ i ];
>>>> ret = subscription.callback.apply( subscription.context, args );

if ( ret === false ) {
break;
}
}

I think this is happening because my call to unsubscribe is removing a
callback from subscriptions[ topic ], but the loop does not expect
this. Sample code as follows:

function oneTimeOnlyCallback(data) {
    amplify.unsubscribe(topic, oneTimeOnlyCallback);
    doSomething(data);

}

amplify.subscribe(topic, oneTimeOnlyCallback);

My question is, is there any way to have a callback unsubscribe itself
from a topic during it receiving the notification from publish?
Without it breaking this loop.

I want to do this as I only want to be notified of a particular topic
once, and don't want the subscription for the topic left registered
after this.

Cheers.

Paul.

Store: Investigate IE 9's web storage behavior

IE 9 appears to have unlimited localStorage and sessionStorage support when using direct access via dot or bracket notation. However, there is a very real limit of 5 MB when using .setItem(). Figure out whether there really is unlimited storage with direct access and switch to using .setItem() for proper error handling if not (this may be a good idea regardless). Also, check if userData is really unlimited.

Avoid multiple subscriptions of same callback to same topic

As of AmplifyJS v1.1.0 there is no check performed about if given callback is already subscribed to the topic. It leads to a problem of several calls to same callback upon message publishing.
Possible way to avoid it is to add some kind of checking of callbacks uniqueness e.g. by using some kind of hash function for them.

Subscriptions with multiple topics will get ignored in certain conditions

I ran into a situation where my subscriptions weren't being called on publish, and through some digging discovered it would happen in the following situation:

// This handler will always work when topic1 or topic2 are published
amplify.subscribe( "topic1 topic2", function () { ... });

....

// Only when topic1 is fired will this ever work, topic3 is ignored.
amplify.subscribe( "topic1 topic3", function () { ... }); 

If you start a multiple topic subscription with a topic that has already been subscribed once, the remaining topics are ignored. If you change up the test in core/test/unit.js, you can see the error:

test( "multiple subscriptions", function() {
    expect( 4 );

    amplify.subscribe( "sub-a-1 sub-a-2 sub-a-3", function() {
        ok( true );
    });
    amplify.publish( "sub-a-1" );

    amplify.subscribe( "sub-b-1 sub-b-2", function() {
        ok( true );
    });

    // All topics but the first one are ignored if the first
    // topic in the string has already been subscribed.
    amplify.subscribe( "sub-b-1 sub-b-3", function() {
        ok( true );
    });

    amplify.publish( "sub-b-2" );
    amplify.publish( "sub-b-2" );
    amplify.publish( "sub-b-3" );
});

Subscribe to multiple pubs with the same function

Sometimes I'd like to handle a number of similar topics with the same function. I'm imagining something like this:

amplify.subscribe(["foo", "bar", "baz"], function(data, topic) {
    alert("got a " + topic + " with " + data); 
});

For that matter, a handy feature for debugging and logging would be subscribeAll().

The error setting is ignored by amplify.request.define

amplify.request.define('custom', 'ajax', {
    url: '/nowhere',
    error: function(){ alert('error'); }
});
// ...
amplify.request({ resourceId: 'custom' });

The alert never shows. But if I move the error param to the amplify.request() call, it works.
See this fiddle (uses HEAD scripts on this github).

Failing storage tests on IE for Windows Phone 7

The storage tests fail for me in IE on Windows Phone 7 (device: LG Optimus 7). I've done a bit of digging, and the problem seems to be with the #userData behavior:

    var div = document.createElement( "div" ),
        attrKey = "amplify";
        div.style.display = "none";
        document.getElementsByTagName( "head" )[ 0 ].appendChild( div );
        if ( div.addBehavior ) {
            div.addBehavior( "#default#userdata" );
            // All good so far
        }

It all works up to this point. (div.addBehavior) evaluates true, and no error is thrown when adding the behavior to the div. However, when you try to load something through the div, I get an error "Object doesn't support this property or method".

            div.load( attrKey ); // Throws error

I've spent some time googling for possibilities, but I can't see anything like this reported elsewhere.

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.