How to use ampersand-model - 10 common examples

To help you get started, we’ve selected a few ampersand-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AmpersandJS / ampersand-collection-rest-mixin / test / main.js View on Github external
var boundSync = Sync.bind(this, method, model, options);
    // emulate syncs that implement a promise for fetch
    return Promise.resolve(boundSync());
};

function endAfter (t, after) {
    var count = 0;
    return function () {
        count++;
        if (after === count) {
            t.end();
        }
    };
}

var Model = AmpersandModel.extend({
    props: {
        name: 'string',
        id: 'number'
    },
    sync: function () {
        this.__syncArgs = arguments;
        return AmpersandModel.prototype.sync.apply(this, arguments);
    }
});

var Collection = AmpersandCollection.extend(RestCollectionMixins, {
    model: Model,
    sync: function () {
        this.__syncArgs = arguments;
        return RestCollectionMixins.sync.apply(this, arguments);
    }
github NLeSC / spot / client / widgets / view-factory.js View on Github external
extendWithErrorBar(Chart, 'bubble', 'bubbleError');

// extend plots with a duration scale type
var extendWithDurationScale = require('./chartjs-duration-scale');
extendWithDurationScale(Chart);

/**
 * A factory producing the Ampersand views corresponding to the different chart types.
 * @example
 * var factory = require('./view-factory')
 *
 * var view = factory.newView(options);
 * @module client/view-factory
 */

var widgetEntry = AmpersandModel.extend({
  props: {
    modelType: {type: 'string', required: true},
    newView: {type: 'any', required: false}
  }
});

var WidgetCollection = Collection.extend({
  model: widgetEntry,
  mainIndex: 'modelType'
});

/**
 * An Ampersand collection containing all available widgets
 */
module.exports.widgets = new WidgetCollection([
  {
github NLeSC / spot / src / widgets / view-factory.js View on Github external
// extend plot with errorbars
var extendWithErrorBar = require('./chartjs-errorbars');
extendWithErrorBar(Chart, 'line', 'lineError');
extendWithErrorBar(Chart, 'bubble', 'bubbleError');
extendWithErrorBar(Chart, 'bar', 'barError');
extendWithErrorBar(Chart, 'horizontalBar', 'horizontalBarError');

// extend plots with a duration scale type
var extendWithDurationScale = require('./chartjs-duration-scale');
extendWithDurationScale(Chart);

// replace the default linear scale with a smarter formatter
var SciLinearFormatter = require('./chartjs-scilinear-formatter');
Chart.scaleService.updateScaleDefaults('linear', { ticks: { callback: SciLinearFormatter } });

var widgetEntry = AmpersandModel.extend({
  props: {
    modelType: {type: 'string', required: true},
    newView: {type: 'any', required: false}
  }
});

var WidgetCollection = Collection.extend({
  model: widgetEntry,
  mainIndex: 'modelType'
});

/**
 * A factory producing the Ampersand views corresponding to the different chart types.
 * @module widgets/view-factory
 */
module.exports.widgets = new WidgetCollection([
github wayfair / tungstenjs / adaptors / ampersand / base_model.js View on Github external
* Base Model - Provides generic reusable methods that child models can inherit from
 */
'use strict';
var AmpersandModel = require('ampersand-model');
var eventBubbler = require('./event_bubbler');
var tungsten = require('../../src/tungsten');
var _ = require('underscore');
var logger = require('../../src/utils/logger');

/**
 * BaseModel
 *
 * @constructor
 * @class BaseModel
 */
var BaseModel = AmpersandModel.extend({
  tungstenModel: true,
  /**
   * Before collections are bound, extend on two extra properties for bubbling
   */
  _initCollections: function() {
    var self = this;
    _.each(this._collections, function(collection, name) {
      self._collections[name] = collection.extend({
        parentProp: name,
        parent: self
      });
    });
    AmpersandModel.prototype._initCollections.call(this);
  },
  initialize: function() {
    /* develblock:start */
github AmpersandJS / ampersand-sync / test / integration.js View on Github external
test('should get a response for read', function (t) {
    t.plan(2);
    var Me = Model.extend({
        url: 'sinon_will_handle_this',
        ajaxConfig: {
            useXDR: false
        },
        props: {
            foo: 'string'
        },
        sync: sync //override with this sync, so fetch doesn't use the stable one from dependencies
    });
    var m = new Me();
    m.on('change', function () {
        //TODO: assert more arguments
        t.equal(m.foo, 'bar');
    });
    m.fetch({
        success: function (data) {
github AmpersandJS / ampersand-sync / test / unit.js View on Github external
test('should allow models to overwrite ajax configs at the model level', function (t) {
    t.plan(7);
    var Me = Model.extend({
        url: '/hi',
        ajaxConfig: {
            useXDR: true,
            xhrFields: {
                withCredentials: true
            },
            headers: {
                accept: 'application/xml'
            }
        }
    });
    var m = new Me();
    m.on('request', function (model, xhr, options, ajaxSettings) {
        t.equal(ajaxSettings.type, 'GET');
        t.equal(ajaxSettings.xhrFields.withCredentials, true);
        t.equal(ajaxSettings.useXDR, true);
github AmpersandJS / ampersand-view / test / renderCollection.js View on Github external
var test = require('tape');
var AmpersandModel = require('ampersand-model');
var AmpersandCollection = require('ampersand-rest-collection');
var AmpersandView = require('../ampersand-view');


var Model = AmpersandModel.extend({
    props: {
        id: 'number',
        name: ['string', true],
        html: 'string',
        url: 'string',
        something: 'string',
        fireDanger: 'string'
    },
    session: {
        active: 'boolean'
    },
    derived: {
        classes: {
            deps: ['something', 'fireDanger', 'active'],
            fn: function () {
                return this.something + this.active;
github AmpersandJS / ampersand-view / test / main.js View on Github external
var test = require('tape');
var AmpersandModel = require('ampersand-model');
var AmpersandCollection = require('ampersand-rest-collection');
var AmpersandView = require('../ampersand-view');

var contains = function (str1, str2) {
    return str1.indexOf(str2) !== -1;
};

var Model = AmpersandModel.extend({
    props: {
        id: 'number',
        name: ['string', true],
        html: 'string',
        url: 'string',
        something: 'string',
        fireDanger: 'string'
    },
    session: {
        active: 'boolean'
    },
    derived: {
        classes: {
            deps: ['something', 'fireDanger', 'active'],
            fn: function () {
                return this.something + this.active;
github AmpersandJS / ampersand-form-view / test / basic.js View on Github external
var test = require('tape').test;
var AmpersandModel = require('ampersand-model');
var AmpersandView = require('ampersand-view');
var AmpersandInputView = require('ampersand-input-view');
var AmpersandCheckboxView = require('ampersand-checkbox-view');
var AmpersandFormView = require('../ampersand-form-view');

var Model = AmpersandModel.extend({
    props: {
        text: 'string',
        textarea: 'string'
    }
});

var isCheckbox = function(el) {
    return el.type === 'checkbox';
};

var getView = function (opts) {
    var formOpts;
    opts = opts || {};
    formOpts = opts.form || {};
    var FormView = AmpersandFormView.extend({
        fields: function () {
github NLeSC / spot / framework / util / time.js View on Github external
function getDatetimeResolution (start, end) {
  var humanized = end.from(start, true).split(' ');
  var units = humanized[humanized.length - 1];
  return refineUnits(units);
}

function getDurationResolution (min, max) {
  var length = moment.duration(max.as('milliseconds') - min.as('milliseconds'), 'milliseconds');
  var humanized = length.humanize().split(' ');

  var units = humanized[humanized.length - 1];
  return refineUnits(units);
}

var TimePart = AmpersandModel.extend({
  props: {
    /**
     * The format string for momentjs
     * @memberof! TimePart
     * @type {string}
     */
    momentFormat: ['string', true],
    /**
     * The format string for postgresql
     * @memberof! TimePart
     * @type {string}
     */
    postgresFormat: ['string', true],
    /**
     * The human readable descprition of the datetime part
     * @memberof! TimePart

ampersand-model

An extension to ampersand-state that adds methods and properties for working with a RESTful API.

MIT
Latest version published 7 years ago

Package Health Score

51 / 100
Full package analysis

Popular ampersand-model functions

Similar packages