enyo.Store and enyo.Source

edited July 2013 in Enyo 2
Seems like can only have one enyo.Store (singleton). What if we have collections/models that come from different sources? How do we change the source to reflect new server URL? Is it save to just change the singleton's source in creation of Collection?


  • There's a singleton for enyo.Store.defaultStore, but not for enyo.Store.
  • Hmm, when I tried to create a second enyo.Store, it said " Uncaught There can only be one enyo.Store active ".
    dataStore = new enyo.Store({source:realDataSource});
    proxyStore = new enyo.Store({source:realProxySource});
  • Ah, I was thinking enyo.Source.defaultSource, not enyo.Store. I'll have to ask Cole about this.
  • The enyo.Store is supposed to be a singleton. You should not need more than one...currently. It does not care where the models come from it manages them as a runtime database. Note, these features aren't fully-baked yet. They are bleeding edge so they will change, although hopefully only in additional features but I can't promise anything at this point. There is no reason that you can't have multiple enyo.Sources, however, but the current implementation of enyo.Store does not have support for that out of the box - but it wouldn't be difficult to manage either. But if the only thing you're changing is the url for the enyo.Collection you're using there is handling to tell the enyo.Source to not modify it thus allowing you to specify the different url at that level.
  • Uhm, okay. So i guess it's okay to change the source for the store? Kind of like:
    dataStore.source = realProxySource;
    Also, I tried overriding the url in my enyo.Model with a "url" parameter. It kept doing the default one though. I had to create a parameter called urlData and then send in options object of {url:this.urlData, queryParams:this.raw()}. Bug or feature? :)
  • I believe a fix is to change Model.js, line 391 from
    	$p.url = $s.url || !$p.noUrl? ($p.name || $p.kindName).replace(/^(.*)\./g,""): "";
    	$p.url = $s.url || (!$p.noUrl? ($p.name || $p.kindName).replace(/^(.*)\./g,""): "");
    if you want to patch your working copy.
  • Thanks for the fix, I'll pass it on to Cole for review and integration.
  • It seems as if I change the dataStore as noted in my post above, send in {url:"/pathtomethod"} as the options struct to fetch, the domain is not updated to the domain specified in new dataStore but rather the domain listed in the old dataStore.

    Should I be doing something to reconstruct the Store or Source after changing the source?
  • The url in the options overrides any URL construction.

    A quick test shows that the domain from your proxy source will be used if you dont pass the URL parameter in your options. From the above thread posts, this was originally done to get around not being able to override url in enyo.Model. This is now fixed in master, so going back to overriding the url in Model, and removing the URL in the options, should give you what you want.

    I'll let someone more familiar with the API to comment on whether the options URL should always be an absolute URL, as opposed to a relative one.
  • Thanks. I did what you suggested and also added rawUrl:true to it.

    When I was passing in URL as {url: this.urlData}, I tried changing urlData to equal domain + url but enyo would prepend the current server name to it anyway.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!