enyo.store enyo.source and collections

I'm trying to experiment with the new feature of enyo 2.3 but I'm a bit lost. Could someone expose a quick fiddle with the details how to display remote data in a dataList using enyo.source enyo.store and a collection?

thanks in advance.

Comments

  • Check out https://github.com/clinuz/FlyApp -- it's a fork of an app that the HP team that works on Ares has been building that Cole has updated. Some of the syntax is about to change again (autobindings go away, computed properties and observers are specified in blocks) as part of a big simplification that we're doing before the 2.3 beta.
  • I had a quick look but I'm still not sure how the controller know the store it needs to use. I will have a more deeper look at the code tomorrow. Thanks for the link!
  • In the Fly app, I think Cole had to do some of the advanced URL features for individual models, but BookingCollection has a url of BookingCollection. It gets appended to the domain (plus the urlPostfix if you need/use it) you set on the Source and that response IS the collection of data.
  • The Store is a singleton object that isn't generally modified. The Source object contains the standard information for all your objects: host, port, urlPrefix:

    I created mine as a kind so I could easily switch between development and production mode. Usually you wouldn't do that.

    enyo.kind({
    name: "ex.DataSource",
    kind: "enyo.Source",
    domain: "serverurl.org",
    secure: false,
    port: 8080,
    urlPostfix: "app"
    });
    Then you need to create a store for your application - I added it in the controllers block (not sure why, I think someone recommended it)

    enyo.kind({
    name: "ex.Application",
    kind: "enyo.Application",
    controllers: [
    {name: "store", kind: "enyo.Store", source: "ex.DataSource"},
    ...
    ],
    });
    The above code generates the url: http://serverurl.org:8080/app which serves as a base url for all your objects. The relative url for the object is appended to that url.

    If you have objects that come from different system, I don't believe there's support for that right now.

    On each individual object, you can declare the relative url on your Model, or in your Controller:

    enyo.kind({
    name: "ex.SomeCoolObject",
    kind: "enyo.Model",
    url: "someCoolObject",
    attributes: {
    ...
    }
    });
    Here's an example of a Collection controller:

    enyo.kind({
    name: "ex.SomeCoolObjectCollectionController",
    kind: "enyo.Collection",
    model: "ex.SomeCoolObject",
    url: "someCoolObject"
    ...
    });
    One other gotcha that I found, specifically for Collection controllers was that the return data is expected to be an array. My endpoint returned a key/value pair where the value was the array, so I had to add this to my controller (where history was the key in the map):

    filterData: function (data) {
    return data.history
    },
    Then, in your DataList:

    {kind: "enyo.DataList", name: "someCoolObjectList",
    fit: true,
    controller: ".app.controllers.someCoolObjectCollectionController",
    childBindingDefaults: {source: ".model", to: ".content"}, components: []

    }

    Hopefully this helps
  • I'd just like to say thanks eric that's the best (only?) explanation of the new MVC stuff I've come across.
  • You're welcome! So far I've been a big fat leech so it's nice to contribute something back :)
Sign In or Register to comment.