npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-data-meta-links-improvements

v0.0.2

Published

POC for https://github.com/emberjs/rfcs/pull/160

Downloads

4

Readme

ember-data-meta-links-improvements

Build Status Ember Observer Score

Proof of Concept for RFC#160.

This addon is a Proof of Concept for RFC#160 which aims to improve the meta and links situation within Ember Data. The goal is to see how the proposed API solves use cases when used in real applications. The outcome of this addon should be a profound test suite which covers all the use cases of the RFC.

:warning: The current implementation heavily relies on patches of Ember Data internals, so it is definitely not encouraged to use in production, as stability and decent performance can not be guaranteed. :warning:

Currently the following improvements are implemented:

  • [x] single record meta data (tests)
    • [x] get record level meta data via record.ref().meta()
    • [x] get response level meta data for single resource via record.ref().meta("response")
  • [ ] links for relationship references
  • [ ] meta and links for finders
  • [ ] get reference for has-many via hasManyRelationship.ref()
  • [ ] get parent reference for relationship reference
    • [ ] belongs to
    • [ ] has many
  • [ ] add hook when new data is received
    • [ ] Model#didReceiveData
  • [ ] further miscellaneous changes
    • [x] get parent reference of link via linkRef.parentRef()

Installation

ember install ember-data-meta-links-improvements

Code samples

Single record meta data

// GET /books/1
// {
//   data: {
//     type: "book",
//     id: 1,
//     meta: {
//       recordLevel: true
//     }
//   },
//   meta: {
//     topLevel: true
//   }
// }
this.store.findRecord('book', 1).then(function(book) {
  // get reference for record
  let bookRef = book.ref();

  // get record level meta data
  let meta = bookRef.meta();
  meta === { recordLevel: true };

  // get response level meta data
  let topLevelMeta = bookRef.meta("response");
  topLevelMeta === { topLevel: true };
});

Has-many links

// GET /books/1
// {
//   data: {
//     type: "book",
//     id: 1,
//     relationships: {
//       chapters: {
//         links: {
//           related: "related-link",
//           self: {
//             href: "self-link",
//             meta: {
//               selfLink: true
//             }
//           }
//         }
//       }
//     }
//   }
// }
this.store.findRecord('book', 1).then(function(book) {
  let chaptersRef = book.hasMany("chapters");

  let related = chaptersRef.links("related");
  related.href() === "related-link";

  let next = chaptersRef.links("self");
  next.meta() === { selfLink: true };

  // GET /self-link
  // {
  //   data: [],
  //   meta: {
  //     isSelf: true
  //   }
  // }
  next.load().then(function(nextArray) {
    nextArray.ref().meta() === { isSelf: true }
  });
});

store.query

// GET /books?page=2
// {
//   data: [{
//     type: "book",
//     id: 1
//   }],
//   links: {
//     next: {
//       href: "/books?page=3",
//       meta: {
//         isLast: true
//       }
//     },
//     prev: {
//       href: "/books?page=1"
//     }
//   },
//   meta: {
//     total: 123
//   }
// }
let books = await this.store.query('book', { page: 2 }).then(function(books) {
  let booksRef = books.ref();

  let prev = booksRef.links("prev");
  prev.href() === "/books?page=1";

  let next = booksRef.links("next");
  next.meta() === { isLast: true };

  let meta = booksRef.meta();
  meta === { total: 123 };
});

// GET /books?page=3
// {
//   data: [{
//     type: "book",
//     id: 1
//   }],
//   links: {
//     prev: {
//       href: "/books?page=2"
//     }
//   },
//   meta: {
//     isLastPage: true
//   }
// }
let next = await books.ref().links("next").load();

next.ref().meta() === { isLastPage: true }

store.findAll

// GET /books
// {
//   data: [{
//     type: "book",
//     id: 1
//   }],
//   links: {
//     self: "self-link"
//   },
//   meta: {
//     total: 123
//   }
// }
let books = await this.store.findAll('book');

let booksRef = books.ref();

let self = booksRef.links("self");
self.href() === "self-link";

let meta = booksRef.meta();
meta === { total: 123 };

// GET /books
// {
//   data: [{
//     type: "book",
//     id: 1
//   }],
//   meta: {
//     total: 456
//   }
// }
await this.store.findAll('book', { reload: true });

booksRef.meta() === { total: 456 };

Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

  • ember serve
  • Visit your app at http://localhost:4200.

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.