GithubHelp home page GithubHelp logo

backbone.hal's People

Contributors

chadkouse avatar mikekelly avatar openfirmware 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

backbone.hal's Issues

Model.clear() clearing embedded/links properties.

Is there a particular reason for not having Model.clear() reset embedded/links properties just like Collection.reset() does for collections? I've been in the need for clearing a model's links/embedded attributes a few times now and doing manually feels pretty repetitive now, specially since I already call clear to get rid of the attributes.

HAL.Collection doesn't support direct instantiation with a JSON array

Monkey = HAL.Model.extend({});
Monkeys = HAL.Collection.extend({ model: Monkey });

monkeys_list = [
  {
    "_links": {
      "self": {
        "href": "/zoo/monkeys/1"
      }
    },
    "id": "1",
    "name": "Petunia",
    "traits": [
      "throws poo",
      "hosts tea parties"
    ],
    "_embeded": {
      "events": [
        {
          "_links": {
            "self": {
              "href": "/zoo/events/343"
            }
          },
          "date": "2012-09-11",
          "description": "Threw a tea party for the Queen. After sharing some particularly lovely shortbread biscuits, started throwing poo."
        },
        {
          "_links": {
            "self": {
              "href": "/zoo/events/301"
            }
          },
          "date": "2011-12-19",
          "description": "Gave a lovely teapot to a child for Chistmas"
        }
      ]
    }
  },
  {
    "_links": {
      "self": {
        "href": "/zoo/monkeys/3"
      }
    },
    "id": "3",
    "name": "Lancelot",
    "traits": [
      "aspires to be a space monkey",
      "dabbles in astronomy and astrophysics"
    ],
    "_embeded": {
      "events": [
        {
          "_links": {
            "self": {
                "href": "/zoo/events/444"
            }
          },
          "date": "2013-03-28",
          "description": "Acted as copilot on the Soyuz TMA-08M mission to the ISS."
        },
        {
          "_links": {
            "self": {
                "href": "/zoo/events/45"
            }
          },
          "date": "2009-07-02",
          "description": "Repremanded after firing a prototype rocket into the nearby Gazelle aviary."
        }
      ]
    }
  }
];


> monkeys = new Monkeys(monkey_list)
  child {links: Object, embedded: Object, attributes: Array[2], length: 0, models: Array[0]…}
> monkeys.models
  []
> monkeys.length
  0

If the Monkey model and collection were standard Backbone objects (instead of HAL objects), you'd get the following:

> monkeys.models
  [ child, child ]
> monkeys.length
  2

Resetting the collection with the JSON array works as expected:

> monkeys = new Monkeys()
> monkeys.reset(monkeys_list)
  child {links: Object, embedded: Object, attributes: Array[2], length: 2, models: Array[2]}
> monkeys.models
  [ child, child]
> monkeys.length
  2

[enhancement] Add missing bower.json.

Hey, maintainer(s) of mikekelly/backbone.hal!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library mikekelly/backbone.hal is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "mikekelly/backbone.hal",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Explain architecture

Could you please explain the architecture of this plugin? Backbone is based on the concept of an id per model object and composition of resource URLs based on this id plus a base URL. How do you override this behavior? Does this cause any undesirable side-effects in Backbone apps?

Also it would be helpful to have a more substantial example of this approach - sort of a sample app.

runtime model definition for collections

We have a HATEAOS API that returns a JSON object of attributes when passed a HTTP OPTIONS request.

im hoping you may be able to help with

  1. can we send an OPTIONS request ?
  2. would it be possible to use the return to define a model ?

Happy to provide more input if needed

Collection is not setting models.

I'm trying to use this library, and it's pretty broken.

Basically, it doesn't perform the way you'd expect a typical Backbone collection application to perform.

When fetching the data, the collection should return an array of models and because Hal.Collection overrides the reset method and tries to parse the cloned object out, the models key doesn't get set.

(function(app, Foo) {
    Foo.Model = HAL.Model.extend();

    Foo.Collection = HAL.Collection.extend({
        model: Foo.Model,
        url: '/api/foo',
        itemRel: 'foos'
    });

    Foo.Views.List = Backbone.View.extend({
        el: '#foos',

        template: _.template($('#foos-list').html()),

        render: function() {
            var self = this,
                foos = new Foo.Collection();

            foos.fetch({
                success: function(collection) {
                    // explodes here!
                    $(self.el).html(self.template({ foos: collection.models }));
                }
            });
        }
    });

    Foo.Router = Backbone.Router.extend({
        routes: {
            'foos': 'getAll'
        },

        getAll: function() {
            var list = new Foo.Views.List();
            list.render();
        }
    });

    var router = new Foo.Router();
})(app, app.module('foo'));

Am I doing this wrong or is this a bug?

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.