Вопрос

I want to represent my wordpress and github activity as a graph network using the javascript library Sigmajs. I am using the google feed api to get RSS feeds of all activity and translating them into nodes and edges on the graph.

But the feed api returns rss results asynchronously. As far as I know sigmajs does not natively support this so im getting undefined references. At this point its only around 20-30 nodes. Some possible solutions are:

  1. Force google feed api to return results synchronously. (not sure how to do this but im assuming it has something to do with appropriate closures?)

  2. Create sigma instance for every feed result and push all graph objects into a single instance. (Not sure its possible and library not well documented enough to try)

  3. Fire an event each time result is returned to ensure sigma only processes one at a time. (Again, not sure how to go about doing this)

Any guidance is very much appreciated. Thanks.

Here is my work so far http://fraseraddison.com More examples and source at http://sigmajs.org/

Это было полезно?

Решение

The solution I went with was firing a custom event. Seems to be working because of javascript's synchronous event handling queue.

function getFeed()
{
    return function callback(result) 
    {
        if (!result.error)
        {
            console.log("Feed retrieved.");
            fireFeed(result.feed);
        }
        else 
            console.log("Feed retrieval failed!");
    }
}

function fireFeed(feed)
{
    //console.log(feed);
    var event = new CustomEvent(
    "newFeed",
    {
        detail: {
            message: feed
        },
        bubbles: true,
        cancelable: true
    }
    );
    document.dispatchEvent(event);
}

document.addEventListener('newFeed', function(e)
        {
            var feed = e.detail.message;
            console.log('feed triggered');
            //console.log(feed);
            buildFeed(feed);
        },true);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top