Comments (9)
Decided to leave this up to people to implement themselves as it's tricky to build this generically.
from ember-model.
Could you show an code example that does that?
from ember-model.
At the very basic level, i guess:
if(typeof model.get('foo') is 'undefined') { model.reload() }
from ember-model.
I was expecting something inside the model class, because usually I don't 'get' the model values.
And how my server will know when to deliver the full data response because reload
will access the same URL as the first time.
I would like to pass the undefined property name to the server too so it knows what your trying to access and then you could return the record in more than two parts if you want to.
from ember-model.
@guilhermeaiolfi one way of doing this would be to check if you got all the attributes from server and set the "incomplete" flag (or whatever you wish to call it) based on that information. So for example if you have attributes title
and description
and you get hash with only title
, you set it as incomplete. Then, when someone tries to access missing attribute (in this case description), you may reload the record.
This use case is often used with list and detailed view - you load part of the data for list and you load the rest when you do reload
as it hits /things/1
URL. If you wish to pass a property to control if the endpoint returns full data, it will be trickier, as reload does not take arguments. In order to support this, you could implement modified version of reload.
Regrading the example implementation, in Travis I do:
- Override
load
, to setincomplete
flag: https://github.com/travis-ci/travis-web/blob/d9d833d1b4f6933a88e4e0b93e12ea0101598b19/assets/scripts/lib/travis/model.coffee#L34-L62 - Override
getAttr
,getBelongsTo
andgetHasMany
methods: https://github.com/travis-ci/travis-web/blob/d9d833d1b4f6933a88e4e0b93e12ea0101598b19/assets/scripts/lib/travis/model.coffee#L64-L78 - Load the rest of the record if it's needed: https://github.com/travis-ci/travis-web/blob/d9d833d1b4f6933a88e4e0b93e12ea0101598b19/assets/scripts/lib/travis/model.coffee#L81-L83
We get incomplete records from pusher, so I can rely on default reload, but other than that you could implement something similar.
from ember-model.
Thank you, @drogus. I'm starting to get the idea. Looking at your code, my first thought was to put needsCompletionCheck
code in unknownProperty
so the reload is done automatically every time the app tries to get something that doesn't exist in the model. You could then check for a list of valid properties and use custom logic to load.
What do you think?
from ember-model.
I would also add that personally I think this is semantically broken - you should always return the whole resource, and if you need partial resources you actually should have two resources - so for the title and description example, you would make a PostDescription model that would belong to the post model and load it separately.
It sounds like in your use case this would make even more sense than in @drogus's use case, because he at least is getting partial information via websocket and then always returning the full record from the REST endpoint. I feel like if you're returning partial information from the REST endpoint depending on a param that's not generally a great thing to do and will get really complex. But not everyone agrees with me on that so don't take my word as gospel!
from ember-model.
What do you think?
I think that using unknownProperty
will not work, because the attributes are defined, they're just not set to any value yet. That's why we added hooks which get called on attributes or relationship access: getAttr
, getBelongsTo
and getHasMany
from ember-model.
@alexspeller the reason why partial records are nice is that if you do something like post.set('title', 'foo')
, you'd also like to see that reflected in the post header. You can do this manually, but it can be a bit annoying, so in a case like that partial records would be nice. Perhaps what would make more sense is not a partial record, but something like a related record, so that the post header and the post are related by id.
from ember-model.
Related Issues (20)
- Ember-cli, declaring an association fails because the model's container is not defined
- Adding dynamic segment to model's urls HOT 1
- Array attr type seems to be broken HOT 4
- Ember-model compatible with Ember-1.11.1 HOT 3
- Compatibility with ember-data HOT 7
- Assertion Failed: You must use Ember.set() to set the `record` property HOT 1
- Compatibility with Ember ~1.13
- Bower doesn't have version 0.0.16 available? HOT 3
- Nested async relation is not fetched
- [Question]: what benefit do you get adding another queue to ember.run?
- hasMany properties do not interact correctly with computed array properties
- Does not work without prototype extensions
- ember-model and ember 2.9.1 HOT 1
- Ember.Model.Store `container` attribute triggers `Cannot read property '__container__' of undefined` on Ember 2.13 production builds HOT 2
- Update Ember Model for Ember 3.0 HOT 2
- Travis CI isn't displaying logs HOT 1
- Replace bower with npm for `ember-source`
- Upgrade node on travis
- Publish ember-model 2.18.0 HOT 1
- ES6 import syntax not working as expected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-model.