Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'ampersand-collection' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
test('issue #82, child collections should not be cleared if they add data to themselves when instantiated', function (t) {
var Widget = State.extend({
props: {
title: 'string'
}
});
var Widgets = Collection.extend({
initialize: function () {
// some collections read from data they have immediate access to
// like localstorage, or whatnot. This should not be wiped out
// when instantiated by parent.
this.add([{title: 'hi'}]);
},
model: Widget
});
var Parent = State.extend({
collections: {
widgets: Widgets
}
});
var parent = new Parent();
t.equal(parent.widgets.length, 1, 'should contain data added by initialize method of child collection');
var test = require('tape');
var mixins = require('ampersand-collection-lodash-mixin');
var Collection = require('ampersand-collection').extend(mixins);
var SubCollection = require('../ampersand-subcollection');
var Model = require('ampersand-state');
var _ = require('lodash');
// our widget model
var Widget = Model.extend({
props: {
id: 'number',
name: 'string',
awesomeness: 'number',
sweet: 'boolean'
}
});
// our base collection
/* global app */
var AmpModel = require('ampersand-model')
var AmpCollection = require('ampersand-collection')
var options = require('../../../options')
var marked = require('../helpers/marked')
var _ = require('../helpers/underscore')
var Communication = require('./communication')
var Comment = require('./comment')
var Participation = require('./participation')
var CommunicationCollection = AmpCollection.extend({
model: Communication
})
var CommentCollection = AmpCollection.extend({
model: Comment
})
var ParticipationCollection = AmpCollection.extend({
model: Participation
})
module.exports = AmpModel.extend({
props: {
id: ['string'],
unread: ['boolean'],
name: ['string'],
description: ['string'],
img: ['string'],
storedImg: ['string'],
site: ['string'],
/* global app */
var AmpModel = require('ampersand-model')
var AmpCollection = require('ampersand-collection')
var options = require('../../../options')
var marked = require('../helpers/marked')
var _ = require('../helpers/underscore')
var Communication = require('./communication')
var Comment = require('./comment')
var Participation = require('./participation')
var CommunicationCollection = AmpCollection.extend({
model: Communication
})
var CommentCollection = AmpCollection.extend({
model: Comment
})
var ParticipationCollection = AmpCollection.extend({
model: Participation
})
module.exports = AmpModel.extend({
props: {
id: ['string'],
unread: ['boolean'],
name: ['string'],
title: ['string'],
description: ['string'],
information: ['string'],
img: ['string'],
/* global app */
var AmpModel = require('ampersand-model')
var AmpCollection = require('ampersand-collection')
var timeSince = require('../helpers/timeSince')
var options = require('../../../options')
var marked = require('../helpers/marked')
var _ = require('../helpers/underscore')
var Comment = require('./comment')
var CommentCollection = AmpCollection.extend({
model: Comment
})
module.exports = AmpModel.extend({
props: {
id: ['string'],
thread: ['string'],
event: ['string'],
kind: ['string'],
member: ['string'],
text: ['string'],
status: ['string'],
posted: ['string'],
updated: ['string']
},
collections: {
/* global app */
var AmpModel = require('ampersand-model')
var AmpCollection = require('ampersand-collection')
var options = require('../../../options')
var marked = require('../helpers/marked')
var _ = require('../helpers/underscore')
var Communication = require('./communication')
var Comment = require('./comment')
var Participation = require('./participation')
var CommunicationCollection = AmpCollection.extend({
model: Communication
})
var CommentCollection = AmpCollection.extend({
model: Comment
})
var ParticipationCollection = AmpCollection.extend({
model: Participation
})
module.exports = AmpModel.extend({
props: {
id: ['string'],
unread: ['boolean'],
name: ['string'],
/* global app */
var AmpModel = require('ampersand-model')
var AmpCollection = require('ampersand-collection')
var options = require('../../../options')
var marked = require('../helpers/marked')
var _ = require('../helpers/underscore')
var Communication = require('./communication')
var Comment = require('./comment')
var Participation = require('./participation')
var CommunicationCollection = AmpCollection.extend({
model: Communication
})
var CommentCollection = AmpCollection.extend({
model: Comment
})
var ParticipationCollection = AmpCollection.extend({
model: Participation
})
module.exports = AmpModel.extend({
props: {
id: ['string'],
unread: ['boolean'],
name: ['string'],
// ShapeGeometry
// SphereBufferGeometry
// SphereGeometry
// TetrahedronBufferGeometry
// TetrahedronGeometry
// TextGeometry
// TorusBufferGeometry
// TorusGeometry
// TorusKnotBufferGeometry
// TorusKnotGeometry
// TubeGeometry
// TubeBufferGeometry
// WireframeGeometry
var GeometryCollection = Collection.extend({
mainIndex: 'name',
// parse: collectionParse,
// toJSON: collectionToJSON,
// serialize: collectionToJSON,
model: makeCollectionModel(GeometryState)
});
/***************************************\
* *
* *
* *
\***************************************/
var LightState = ThreeState.extend({
props: {
idAttribute: 'name',
typeAttribute: 'type',
props: {
type: ['string', false, null],
name: ['string', false, null]
},
children: {
color: Color
}
});
MaterialState.types = {};
var MaterialCollection = Collection.extend({
mainIndex: 'name',
// parse: collectionParse,
// toJSON: collectionToJSON,
// serialize: collectionToJSON,
model: makeCollectionModel(MaterialState)
});
/***************************************\
* *
* *
* *
\***************************************/
var GeometryState = ThreeState.extend({
}
};
}
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);
}
});
test('Existence of methods', function (t) {
t.plan(5);
var collection = new Collection();
t.ok(typeof collection.fetch === 'function');
t.ok(typeof collection.create === 'function');
t.ok(typeof collection.sync === 'function');
t.ok(typeof collection.getOrFetch === 'function');