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

ko-modelize

v3.5.0

Published

REST model interface for KnockoutJS

Downloads

3

Readme

Travis Build
Bower Release Bower License

Modelize

Modelize is a small model/data interface for REST APIs using KnockoutJS. It also integrates encryption functionality in combination with SJCL.

Basic Usage

Page setup first, include all required scripts:

<!-- jQuery -->
<script src="/vendor/jquery/dist/jquery.min.js"></script>
<!-- jQuery rest -->
<script src="/vendor/jquery.rest/dist/1/jquery.rest.min.js"></script>
<!-- Knockout -->
<script src="/vendor/knockoutjs/dist/knockout.js"></script>
<!-- SJCL (optional) -->
<script src="/vendor/sjcl/sjcl.js"></script>
<!-- Modelize -->
<script src="/vendor/modelize/dist/modelize.min.js"></script>

Setup a connector:

api_connector = new RESTConnector('/api/')

Then define some models in coffeescript:

# Post model with a simple 1:n relation for comments and two editable data fields
Post = Modelize
  api: 'posts'
  connector: api_connector
  has_many:
    comment:
      model: 'Comment'
  editable: [
    'title',
    'content' ]

# The corresponding comment model
Comment = Modelize
  api: 'posts'
  connector: api_connector
  belongs_to:
    post:
      model: 'Post'
  editable: [
    'content']

But basically the model can be as short as just this:

Model = Modelize
  api: 'stuff'
  connector: api_connector

Using your models:

# Get all (published e.g.) posts and put them in the observable array @posts
Post.get { status: 'published' }, @posts
# You can also define custom methods for retrieval
Post.get { id: 1 }, (post) =>
  console.log post

Docs

Relations

has_one and belongs_to relations

has_one relations add a relation_id field to the main model.

relation()
relation_get([parameters], [callbackOrObservable])

has_many relations

relations()
# For Example:
Post.comments()

has_many relation access is always extended with an 's'. So relation 'comment', turns to 'comments'

relation_get([parameters], [callbackOrObservable])
# For Example:
Post.comment_get()
# Or
Post.comment_get({ status: 'not_spam' })
relation_add([parameters], [callbackOrObservable])
relation_destroy([callback])

Observable types

editable
functions
observable
computed
purecomputed

Predefined functions

create(callback)
update(params, callback)
export([id])

Containers

Containers are defined just like the main models, with the exception that they only support the observable types and don't have any api/connector or relational options.

Definition

MetaInformation = Container
  editable: [
    'title',
    'description'
  ]

Usage and options

Post = Modelize
  container:
    MetaInformation:
      first_class: true
datahandler: [object, default: instance of JSONHandler]
first_class: [bool, default: false]

If this is set to true, then all editables are mapped to the main model object and available for direct editing.

container: [string, default: container option name]
field: [string, default: container option name]