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

next-core-model

v3.1.5

Published

The Augmented.js Next - Model & Collection.

Downloads

134

Readme

next-core-model

Augmented.js Next Core - Model & Collection

API

Table of Contents

AbstractModel

Extends AugmentedObject

AbstractModel Supports:

Parameters

  • attributes
  • options (optional, default {})
  • args ...any

uriRoot

uri root property

Properties

  • uriRoot string Root of the URI

schema

Schema property

Properties

  • schema object The JSON schema from this model

validationMessages

Validation Message property

Properties

  • validationMessages object The property holding validation message data

get

Get the attribute form the Model

Parameters

  • attribute

Returns any The model attribute

set

Set a hash of model attributes on the object, firing "change". This is the core primitive operation of a model, updating the data and notifying anyone who needs to know about the change in state.

Parameters

  • key
  • value
  • options

escape

Escape the attribute data

Parameters

  • attribute

has

Has an attribute in the Model

Parameters

  • attribute

Returns bolean Returns true if exists

matches

Special-cased proxy to underscore's matches method.

Parameters

  • attrs

unset

Remove an attribute from the model, firing "change". unset is a noop if the attribute doesn't exist.

Parameters

  • attr
  • options

clear

Clear all attributes on the model, firing "change".

Parameters

  • options

toJSON

Transforms model to pure toJSON

fetch

Fetch the model from the server, merging the response with the model's local attributes. Any changed attributes will trigger a "change" event.

Parameters

  • options (optional, default {})

fetch

fetch - Fetches the model as a 'get'

Parameters

  • options

save

Set a hash of model attributes, and sync the model to the server. If the server returns an attributes hash that differs, the model's state will be set again.

Parameters

  • key
  • val
  • options (optional, default {})

save

save - Saves the model as a 'create'

Parameters

  • options

destroy

Destroy this model on the server if it was already persisted. Optimistically removes the model from its collection, if it has one. If wait: true is passed, waits for the server to respond before removal.

Parameters

  • options (optional, default {})

destroy

destroy - Deletes the model as a 'delete'

Parameters

  • options

url

Default URL for the model's representation on the server -- use uri()

Meta

  • deprecated: use uri

uri

Default URI for the model's representation on the server -- if you're using restful methods, override this to change the endpoint that will be called.

keys

Keys of the attributes in this Model

values

Values of the attributes in this Model

parse

Converts a response into the hash of attributes to be set on the model. The default implementation is just to pass the response along.

Parameters

  • resp
  • options

clone

Create a new model with identical attributes to this one.

isNew

A model is new if it has never been saved to the server, and lacks an id.

hasChanged

Determine if the model has changed since the last "change" event. If you specify an attribute name, determine if that attribute has changed.

Parameters

  • attr

changedAttributes

Return an object containing all the attributes that have changed, or false if there are no changed attributes. Useful for determining what parts of a view need to be updated and/or what attributes need to be persisted to the server. Unset attributes will be set to undefined. You can also pass an attributes object to diff against the model, determining if there would be a change.

Parameters

  • diff

previous

Get the previous value of an attribute, recorded at the time the last "change" event was fired.

Parameters

  • attr

previousAttributes

Get all of the attributes of the model at the time of the previous "change" event.

supportsValidation

supportsValidation - Returns True if this model supports validation

Returns boolean Returns True if this model supports validation

isValid

isValid - Returns True if this model is valid Runs two level validation, attribute-level then JSON Schema

Parameters

  • options (optional, default {})

Returns boolean Returns True if this model is valid

validate

Validates the model

Returns array Returns array of messages from validation

getValidationMessages

Gets the validation messages only in an array

Returns array Returns array of messages from validation

sync

Sync model data (Should override as needed)

Parameters

  • method
  • model
  • options

reset

reset - clear and rewrite the model with passed data

Parameters

  • data object The data to replace the model with (optional)

isEmpty

isEmpty - returns true is the model is empty

Returns boolean returns true is the model is empty

toString

toString - returns the model data as a string

Returns string returns the model data as a string

update

update - Updates the model as a 'update'

Parameters

  • options

AbstractCollection

Extends AugmentedObject

Abstract Augmented Collection Supports:

Parameters

  • models
  • options (optional, default {})

preinitialize

Schema property

Parameters

  • models
  • options

Properties

  • schema object The JSON schema from this collection

preinitialize

Validation Message property

Parameters

  • models
  • options

Properties

  • validationMessages object The property holding validation message data

toJSON

The JSON representation of a Collection is an array of the models" attributes.

add

Add a model, or list of models to the set. models may be Models or raw JavaScript objects to be converted to Models, or any combination of the two.

Parameters

  • models
  • options (optional, default {})

Meta

  • deprecated: call addModels

addModels

Add a model, or list of models to the set. models may be Models or raw JavaScript objects to be converted to Models, or any combination of the two.

Parameters

  • models (Model | array) Models to add or single model
  • options object Option s to add

Returns Model Return the added (or merged) model (or models).

removeModels

Remove a model, or a list of models from the set.

Parameters

  • models (optional, default [])
  • options (optional, default {})

set

Update a collection by set-ing a new list of models, adding new ones, removing models that are no longer present, and merging models that already exist in the collection, as necessary. Similar to Model#set, the core operation for updating the data contained by the collection.

Parameters

  • models
  • options (optional, default {})

reset

When you have more items than you want to add or remove individually, you can reset the entire set with a new list of models, without firing any granular add or remove events. Fires reset when finished. Useful for bulk operations and optimizations.

Parameters

  • models
  • options

push

Add a model to the end of the collection.

Parameters

  • model
  • options

pop

Remove a model from the end of the collection.

Parameters

  • options

unshift

Add a model to the beginning of the collection.

Parameters

  • model
  • options

shift

Remove a model from the beginning of the collection.

Parameters

  • options

slice

Slice out a sub-array of models from the collection.

Parameters

  • args ...any

get

Get a model from the set by id, cid, model object with id or cid properties, or an attributes object that is transformed through modelId.

Parameters

  • obj

has

Returns true if the model is in the collection.

Parameters

  • obj

at

Get the model at the given index.

Parameters

  • index

find

find the model that matches these properties

Parameters

  • attrs object properties to match

Returns Augmented.AbstractModel model that matched

filter

filter the models that match these properties

Parameters

  • attrs object properties to match

Returns array models that matched

where

Return models with matching attributes. Useful for simple cases of filter.

Parameters

  • attrs object properties to match
  • first

Returns (Model | array) models that matched

findWhere

Return the first model with matching attributes. Useful for simple cases of find.

Parameters

  • attrs

sort

Force the collection to re-sort itself. You don"t need to call this under normal circumstances, as the set will maintain sort order as each item is added.

Parameters

  • options (optional, default {})

pluck

Pluck an attribute from each model in the collection.

Parameters

  • attr

fetch

Fetch the collection

Parameters

  • options

create

Create a new instance of a model in this collection. Add the model to the collection immediately, unless wait: true is passed, in which case we wait for the server to agree.

Parameters

  • model
  • options

parse

parse converts a response into a list of models to be added to the collection. The default implementation is just to pass it through.

Parameters

  • resp
  • options

clone

Create a new collection with an identical list of models as this one.

modelId

Define how to uniquely identify models in the collection.

Parameters

  • attrs

values

Get an iterator of all models in this collection.

keys

Get an iterator of all model IDs in this collection.

entries

Get an iterator of all [ID, model] tuples in this collection.

supportsValidation

supportsValidation - Returns True if this collection supports validation

Returns boolean Returns True if this collection supports validation

isValid

isValid - Returns True if this collection is valid

Returns boolean Returns True if this collection is valid

getValidationMessages

getValidationMessages - Returns the validation messages

Returns array Returns the message is an array of objects.

validate

Validates the collection

Returns array Returns array of message from validation

sync

Collecion.sync

Parameters

  • method
  • model
  • options

save

save - Saves the collection as a "create"

Parameters

  • options (optional, default {})

update

update - Updates the collection as an "update"

Parameters

  • options (optional, default {})

remove

remove - Remove from the collection as a "delete"

Parameters

  • options (optional, default {})

sortByKey

sortByKey - Sorts the collection by a property key

Parameters

isEmpty

isEmpty - returns true is the collection is empty

Returns boolean returns true is the collection is empty

size

size - returns the size of the collection

Returns number returns the size of the collection

toString

toString - returns the collection data as a string

Returns string returns the collection data as a string

CollectionIterator

A CollectionIterator implements JavaScript's Iterator protocol, allowing the use of for of loops in modern browsers and interoperation between Collection and other JavaScript functions and third-party libraries which can operate on Iterables.

Parameters

  • collection
  • kind

next

Next model in collection Once exhausted, remove the reference to the collection so future calls to the next method always return done.