Git Product home page Git Product logo

ember-resource's People

Contributors

aghassipour avatar caligo-mentis avatar jamesarosen avatar jish avatar pangratz avatar rapheld avatar shajith avatar staugaard avatar stefl avatar whump avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ember-resource's Issues

Partial Load Cascades to Fetch

Given a resource with two properties and a third that depends on the first two, if you create an instance with one but not the other, the full resource will be fetched even if no client ever asks for the dependent property. For example:

MyModel = SC.Resource.define({
  schema: {
    foo: String,
    bar: String
  }
}).extend({
  baz: function()  {
    return this.get('foo') + this.get('bar');
  }).property('foo', 'bar').cacheable()
});

aModel = MyModel.create({ id: 12, foo: 'FOO' });

Immediately after that last line, Sproutcore notifies the model that foo changed (from undefined to FOO), which causes baz to be recalculated, which causes bar to be requested, which causes the model to be fetched.

The correct behavior is that only if an outside client (e.g. a view) requests bar or baz does the model get fetched.

Cannot add to collections that have not been successfully fetched

When a ResourceCollection is created, its content is undefined (unless you pass in an Array for the content, in which case it's a non-fetchable collection), which means that attempts to pushObject will fail silently. It's fine to say that you can't add items to the collection until it's been fetched. If the fetch fails, however, content is still undefined. I think the proper solution is to add a fail callback to the fetch deferred object that creates an empty content array.

Uncaught TypeError: Cannot call method 'property' of undefined

Hi,
I am trying to define Resource objects to connect to an API in the following format:

{
  blocks: [
    {
      id: 1,
      name: "Search Action"
    },
    {
      id: 2,
      name: "Refresh Action"
    }
  ]
}

When I use an API in this format with a Resource I get the error in title

uncaught TypeError: Cannot call method 'property' of undefined

I have put more details about this problem in these SO questions:
http://stackoverflow.com/questions/12415302/type-error-using-ember-resource-with-ember-js-and-rails
http://stackoverflow.com/questions/12443125/how-can-i-connect-array-of-objects-returned-from-an-api-to-ember-resource

I now suspect it may be a bug, so decided to report here. But if it is something I am doing wrong, I would appreciate any help.

Fails to Start Fetching on IE7 and IE8

It actually seems like an Ember bug. It doesn't start fetching on IE7 and IE8.

Follow the steps below to reprod the issue:

  1. wget https://github.com/downloads/azer/ember-resource/sc-resource-fetch-bug.tar.gz
  2. tar xvvf sc-resource-fetch-bug.tar.gz & cd sc-resource-fetch-bug
  3. make publish
  4. open http://localhost:8000 with a modern browser
  5. make sure that a request has been sent to "/node/$subdomain/api/v2/users/3". Ignore the 404 error.
  6. open same URL with IE7 or IE8
  7. Monitor the network activities using Fiddler or the output of "make publish"
  8. IE7 and IE8 doesn't send any request to the resource URL.

Does ember-resource support Ember's computed properties?

Hi there,
I've been trying out ember-resource and it seems to break the computer property functions I previously had in my classes (which were regular Ember.Objects previous to trying ember-resource).

Here's an example of what I'm trying to do:
http://jsfiddle.net/sohara/wqhwn/8/

Is this not supported? Or is there a different way of defining computed properties within an Ember.Resource?
Thanks,
Sean

Document or remove _ dependency

We should either clearly document that _ is a requirement or figure out a more SC-only way to write the things that currently use it.

Observers are not firing on property changes

I see that SC.Resource is an extension of SC.Object, however, it doesn't look like it's respecting observers. Is this by design?

As a demo, here is some test code:

var A = SC.Object.extend({ name: null });
var B = SC.Resource.define({
  url: '/b', schema: { name: String }
});

var a = A.create({
  obs: function() { SC.Logger.info("A!!!"); }.observes('name')
});

var b = B.create({
  obs: function() { SC.Logger.info("B!!!"); }.observes('name')
});

a.set('name', 'Foo');
b.set('name', 'Bar');

This code produces the following output:

A!!!

The observer in the SC.Resource is not fired.

Add support for polymorphic has-many associations

It's possible to "fake" a polymorphic association by using a "class" whose constructor is really a factory method for other classes. Unfortunately, this falls short when the different classes have different parse methods. I suggest the following syntax:

MyBlog.Post = SC.Resource.define({
  comments: {
    type: SC.ResourceCollection,
    itemType: function(json) { return SC.get('MyBlog.%@'.fmt(json.type)); },
    url: '/posts/%@/comments'
  }
})

If itemType is a function, it is called with each of the data objects in turn to get the parser and constructor.

Bindings not syncing before save()

I am chaining the saving of a few resources. When the first resource is saved, it is updated with the ID that I need to save the second resource (via a binding). However, when I use jQuery.Deferred callbacks to trigger the chain, the bindings from the first objects don't propagate to the second object.

I'm wondering whether it makes sense to call SC.run.sync() before calling toJSON() in the save() function. I'm not sure whether it's the best solution to do it synchronously because the save() call might be tied to a user action.

Here's some demo code that manifests the issue:

R = SC.Resource.define({
  url: '/url',
  schema: {
    id:  String,
    foo: String
  }
});

Demo = SC.Application.create({
  foo: 'hello',
  r: R.create({
    fooBinding: 'Demo.foo'
  })
});

// run.once() to allow the original value to sync
SC.run.once(Demo, function() {
  Demo.set('foo', 'world');
  Demo.r.save();
});

In this test, foo=hello is sent to the server, not foo=world

Schema cannot be reopened

When sharing code across multiple projects, it makes sense to put core classes in a shared library. Individual projects would then reopen the core classes to add functionality specific to their use-cases. For example:

User = Ember.Resource.define({
  organization: { type: 'Organization', nested: true }
});
User.reopenSchema({
  posts: {
    type: Ember.ResourceCollection,
    itemType: 'BlogPost',
    url: '/users/%@/posts'
  }
});

Support inverse relationships

In nested hasOne and hasMany associations, it's useful to have the associated objects have pointers back to the origin object. This can't be done by overriding init since the object won't have been fetched and thus the associated objects may not exist. It can't be done by overriding the association method and calling _super because the association is defined first in this class, not a parent.

I suggest the following:

Owner = Ember.Resource.define({
  foo: {
    type: 'Foo',
    nested: true,
    inverse: 'owner'
  },
  bars: {
    type: Ember.ResourceCollection,
    itemType: 'Bar',
    nested: true,
    inverse: 'owner'
  }
});

This would declare owner properties on the associated Foos and Bars. For example

someOwner.getPath('foo.owner') === someOwner; // true

Collection sort order in IE?

I have an app using Ember Resource (thanks!) and it displays a set of "Spaces" that have many "Conversations" that have many "Thoughts".

If I view a collection of Thoughts in Webkit they all appear in order of creation (and the order they appear in the JSON). In IE8 however they appear out of order - seemingly at random.

Is this an Ember bug or something I am doing wrong with Ember Resource?

Is there perhaps some way of specifying a sort order on the loaded "content" of a controller and how it is displayed in a collection of views?

add documentation

Include examples of resource URL, schema, has-one, has-many.

Once #3 is resolved, add subclassing resources.

Add ability to subclass definitions

given a resource class:

Foo = SC.Resource.define({
  url: '/foos',
  schema: {
    id: Number,
    name: String,
    created_at: Date
  }
});

I'd like to be able to subclass Foo and reopen the schema. Perhaps something like

Bar = Foo.define({
  url: '/bars',
  schema: $.extend({}, Foo.schema, {
    foo: { type: Foo, path: "foo_id" }
  })
});

Cannot set value on a nested has-many collection

Example:

Klass = Em.Resource.define({
  schema: {
    children: {
      type: Em.ResourceCollection,
      itemType:Object,
      nested: true
    }
  }
});

k = Klass.create({});
k.set('children', [ { name: 'Harold' } ]);
k.get('children'); // undefined

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.