GithubHelp home page GithubHelp logo

Comments (11)

rague avatar rague commented on May 16, 2024

It seems that it's expected with fixtures: you can't load it twice. (handled by fixtures.hasLoaded property - fixture_adapter.js).

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

hasLoaded goes back to undefined before setting the new data in App.Person.FIXTURES. Other than that, the code is shared between all adapters.

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

So, I looked it over and it seems that in store.updateModelArray we have:

if (shouldBeInArray && !alreadyInArray) {
      modelArrays.add(array);
      content.pushObject(clientId);
    } else if (!shouldBeInArray && alreadyInArray) {
      modelArrays.remove(array);
      content.removeObject(clientId);
    }

but when it should update the data it has shouldBeInArray as true and alreadyInArray as true also. And this case isn't being considered in the code.

But I'm not sure how I should proceed here. "content" seems to have a list of indexes but what about "modelArrays"? I'm not sure what it suppose to be or do. I know it's a SC.OrderedSet but in my example modelArrays.list has 2 objects and there is 4 in my store. I need some tips here. Thanks.

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

I've done something that seems to work:

updateModelArray: function(array, filter, type, clientId, hash) {
    var shouldBeInArray;

    if (!filter) {
      shouldBeInArray = true;
    } else {
      shouldBeInArray = filter(hash);
    }

    var content = get(array, 'content');
    var alreadyInArray = content.indexOf(clientId) !== -1;

    var modelArrays = this.modelArraysForClientId(clientId);

    if (shouldBeInArray && !alreadyInArray) {
      modelArrays.add(array);
      content.pushObject(clientId);
    } else if (!shouldBeInArray && alreadyInArray) {
      modelArrays.remove(array);
      content.removeObject(clientId);
    } else if (shouldBeInArray && alreadyInArray) {
        var models = get(this, 'models');
        this.didUpdateModel(models[clientId], hash);
    }
  },

The last "else if" being the relevant part.

What do you think?

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

It seems that bbf044b should fix this as well. I'll try that monday.

from data.

wycats avatar wycats commented on May 16, 2024

I'm closing this ticket. If it's still an issue, please let me know.

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

Well, I updated the jsfiddle to use the last changes: http://jsfiddle.net/5n2LU/8/

But it doesn't work yet.

findMany calls loadMany internatlly in the fixtureAdapter, so it should update those records in the store, but that's not happening.

from data.

wycats avatar wycats commented on May 16, 2024

The semantics of findMany are that if the IDs are already in the store, the store doesn't go back to the adapter to get more data.

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

Al'right, but loadMany shouldn't update the store?

Even tho there is a if (fixtures.hasLoaded) { return; } in the code, hasLoaded is undefined in the jsfiddle example in both findMany calls.

findMany will call find that will call loadMany. Here it is the code I'm talking about:

find: function(store, type, id) {
    var fixtures = type.FIXTURES;

    ember_assert("Unable to find fixtures for model type "+type.toString(), !!fixtures);
    if (fixtures.hasLoaded) { return; }

    setTimeout(function() {
      store.loadMany(type, fixtures);
      fixtures.hasLoaded = true;
    }, 300);
  }

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

I really think the else if that I mentioned earlier in this thread, inside the updateModelArray function, is a case that is not being dealt and seems the source of this problem.

from data.

guilhermeaiolfi avatar guilhermeaiolfi commented on May 16, 2024

Since another person in the IRC channel had this problem:

how can i refresh data of ember-data?? i loaded an array of items with find and now i would like to refresh them?
should i use findMany?? calling again findAll does not request anything, i assumed is returning the cache```

He managed to update the records:

for findAll i fixed by Yn.store.typeMapFor(Yn.Product).findAllCache = null;```

But that doesn't seem right. Is it?

from data.

Related Issues (20)

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.