Skip to content

Instantly share code, notes, and snippets.

@robrichard
Last active August 29, 2015 13:56
Show Gist options
  • Save robrichard/9261001 to your computer and use it in GitHub Desktop.
Save robrichard/9261001 to your computer and use it in GitHub Desktop.
Before and after browserify
"use strict";
var SoaModel = require('@bunsen/models/SoaModel'),
Shipment = SoaModel.extend();
module.exports = bunsen.Shipment = Shipment;
var Backbone = require('Backbone'),
_ = require('underscore'),
endpoints = require('@bunsen/libraries/endpoints'),
Transaction = require('@bunsen/models/ecomm/Transaction');
_.extend(Shipment.prototype, {
idAttribute: "id",
url : function () {
return endpoints.shipment(this.get(this.idAttribute));
},
relations: SoaModel.createRelations([
{
type: Backbone.One,
key: 'transaction',
relatedModel: Transaction,
}
])
});
(function () {
"use strict";
bunsen.Shipment = bunsen.SoaModel.extend({
idAttribute: "id",
url : function () {
return endpoints.shipment(this.get(this.idAttribute));
},
relations: bunsen.SoaModel.createRelations([
{
type: Backbone.One,
key: 'transaction',
relatedModel: 'bunsen.Transaction',
}
])
});
}());
"use strict";
var SoaModel = require('@bunsen/models/SoaModel'),
Transaction = SoaModel.extend();
module.exports = bunsen.Transaction = Transaction;
var Backbone = require('Backbone'),
_ = require('underscore'),
endpoints = require('@bunsen/libraries/endpoints'),
Offer = require('@bunsen/models/ecomm/Offer'),
Offers = require('@bunsen/collections/ecomm/Offers'),
CurrencyConversionRate = require('@bunsen/models/ecomm/CurrencyConversionRate'),
Shipment = require('@bunsen/models/ecomm/Shipment');
_.extend(Transaction.prototype, {
idAttribute: "id",
url : function () {
return endpoints.transaction(this.get(this.idAttribute));
},
relations: SoaModel.createRelations([
{
type: Backbone.Many,
key: 'offers',
relatedModel: Offer,
collectionType: Offers
},
{
type: Backbone.Many,
key: 'currencyConversionRates',
relatedModel: CurrencyConversionRate
},
{
type: Backbone.One,
key: 'shipment',
relatedModel: Shipment
}
]),
createOffer: function () {
var offer = new Offer({
amount: 1234
});
return offer.save();
}
});
(function () {
"use strict";
bunsen.Transaction = bunsen.SoaModel.extend({
idAttribute: "id",
url : function () {
return endpoints.transaction(this.get(this.idAttribute));
},
relations: bunsen.SoaModel.createRelations([
{
type: Backbone.Many,
key: 'offers',
relatedModel: 'bunsen.Offer',
collectionType: 'bunsen.Offers'
},
{
type: Backbone.Many,
key: 'currencyConversionRates',
relatedModel: 'bunsen.CurrencyConversionRate'
},
{
type: Backbone.One,
key: 'shipment',
relatedModel: bunsen.Shipment
}
]),
createOffer: function () {
var offer = new bunsen.Offer({
amount: 1234
});
return offer.save();
}
});
}());
@robrichard
Copy link
Author

Assume bunsen.Shipment also has a relation to bunsen.Transaction.

Issues:

  • circular references
  • string references
  • mix of string references and global namespace object references
  • reference to same object as both a string and object

Questions

  • absolute or relative paths?
  • expose on global namespace even when in a modular environment?
  • this vs window in factory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment