Skip to content

Instantly share code, notes, and snippets.

@opsb
Created September 24, 2015 07:58
Show Gist options
  • Select an option

  • Save opsb/d0c9b6e5286f17d15379 to your computer and use it in GitHub Desktop.

Select an option

Save opsb/d0c9b6e5286f17d15379 to your computer and use it in GitHub Desktop.
diff build-babel/orbit-common-jsonapi.js build/orbit-common-jsonapi.js
< 'use strict';
<
14c12
< resourceKey: function resourceKey(type) {
---
> resourceKey: function(type) {
18,19c16,17
< resourceType: function resourceType(type) {
< return strings.dasherize(this.schema.pluralize(type));
---
> resourceType: function(type) {
> return strings.dasherize( this.schema.pluralize(type) );
22,23c20,21
< resourceLink: function resourceLink(type, link) {
< return strings.dasherize(link);
---
> resourceLink: function(type, link) {
> return strings.dasherize( link );
26,27c24,25
< resourceAttr: function resourceAttr(type, attr) {
< return strings.dasherize(attr);
---
> resourceAttr: function(type, attr) {
> return strings.dasherize( attr );
30,31c28,29
< typeFromResourceType: function typeFromResourceType(resourceType) {
< return strings.camelize(this.schema.singularize(resourceType));
---
> typeFromResourceType: function(resourceType) {
> return strings.camelize( this.schema.singularize(resourceType) );
34,35c32,33
< attrFromResourceAttr: function attrFromResourceAttr(type, resourceAttr) {
< return strings.camelize(resourceAttr);
---
> attrFromResourceAttr: function(type, resourceAttr) {
> return strings.camelize( resourceAttr );
38,39c36,37
< linkFromResourceLink: function linkFromResourceLink(type, resourceLink) {
< return strings.camelize(resourceLink);
---
> linkFromResourceLink: function(type, resourceLink) {
> return strings.camelize( resourceLink );
42c40
< resourceId: function resourceId(type, id) {
---
> resourceId: function(type, id) {
69c67
< idFromResourceId: function idFromResourceId(type, resourceId) {
---
> idFromResourceId: function(type, resourceId) {
92c90
< serialize: function serialize(type, records) {
---
> serialize: function(type, records) {
104c102
< serializeRecords: function serializeRecords(type, records) {
---
> serializeRecords: function(type, records) {
107c105
< records.forEach(function (record) {
---
> records.forEach(function(record) {
114c112
< serializeRecord: function serializeRecord(type, record) {
---
> serializeRecord: function(type, record) {
125c123
< serializeId: function serializeId(type, record, json) {
---
> serializeId: function(type, record, json) {
132c130
< serializeType: function serializeType(type, record, json) {
---
> serializeType: function(type, record, json) {
136c134
< serializeAttributes: function serializeAttributes(type, record, json) {
---
> serializeAttributes: function(type, record, json) {
139c137
< Object.keys(modelDef.attributes).forEach(function (attr) {
---
> Object.keys(modelDef.attributes).forEach(function(attr) {
144c142
< serializeAttribute: function serializeAttribute(type, record, attr, json) {
---
> serializeAttribute: function(type, record, attr, json) {
155c153
< serializeLinks: function serializeLinks(type, record, json) {
---
> serializeLinks: function(type, record, json) {
167c165
< value = Object.keys(value).map(function (id) {
---
> value = Object.keys(value).map(function(id) {
178a177
>
183c182
< serializeRelationshipIdentifier: function serializeRelationshipIdentifier(type, id) {
---
> serializeRelationshipIdentifier: function(type, id) {
190c189
< deserialize: function deserialize(type, id, data) {
---
> deserialize: function(type, id, data) {
202c201
< data.included.forEach(function (recordData) {
---
> data.included.forEach(function(recordData) {
216c215
< deserializeLink: function deserializeLink(data) {
---
> deserializeLink: function(data) {
219c218
< return data.map(function (linkData) {
---
> return data.map(function(linkData) {
224a224
>
230c230
< deserializeRelationshipIdentifier: function deserializeRelationshipIdentifier(data) {
---
> deserializeRelationshipIdentifier: function(data) {
238,239c238,239
< deserializeRecords: function deserializeRecords(type, ids, data) {
< return data.map(function (recordData, i) {
---
> deserializeRecords: function(type, ids, data) {
> return data.map(function(recordData, i) {
245c245
< deserializeRecord: function deserializeRecord(type, id, data) {
---
> deserializeRecord: function(type, id, data) {
270c270
< deserializeKey: function deserializeKey(type, record, key, value) {
---
> deserializeKey: function(type, record, key, value) {
274c274
< deserializeAttributes: function deserializeAttributes(type, record, json) {
---
> deserializeAttributes: function(type, record, json) {
276c276
< Object.keys(modelDef.attributes).forEach(function (attr) {
---
> Object.keys(modelDef.attributes).forEach(function(attr) {
285c285
< deserializeAttribute: function deserializeAttribute(type, record, attr, value) {
---
> deserializeAttribute: function(type, record, attr, value) {
289c289
< assignLinks: function assignLinks(type, records) {
---
> assignLinks: function(type, records) {
297c297
< Object.keys(records.included).forEach(function (includedType) {
---
> Object.keys(records.included).forEach(function(includedType) {
303,304c303,304
< assignLinksToRecords: function assignLinksToRecords(type, records) {
< records.forEach(function (record) {
---
> assignLinksToRecords: function(type, records) {
> records.forEach(function(record) {
309c309
< assignLinksToRecord: function assignLinksToRecord(type, record) {
---
> assignLinksToRecord: function(type, record) {
316c316
< Object.keys(record.__relationships).forEach(function (link) {
---
> Object.keys(record.__relationships).forEach(function(link) {
326c326
< linkValue.forEach(function (resourceId) {
---
> linkValue.forEach(function(resourceId) {
329a330
>
332a334
>
333a336
>
340,341d342
< });
< 'use strict';
342a344
> });
349c351
< init: function init(options) {
---
> init: function(options) {
357c359
< options.cacheOptions.processors = options.cacheOptions.processors || [SchemaConsistencyProcessor['default'], CacheIntegrityProcessor['default'], DeletionTrackingProcessor['default']];
---
> options.cacheOptions.processors = options.cacheOptions.processors || [SchemaConsistencyProcessor['default'], CacheIntegrityProcessor['default'], DeletionTrackingProcessor['default']];
360,362d361
< console.log('hello es6');
< console.log('hello es5');
<
365,368c364,367
< this.namespace = options.namespace || this.namespace;
< this.host = options.host || this.host;
< this.headers = options.headers || this.headers;
< this.SerializerClass = options.SerializerClass || this.SerializerClass;
---
> this.namespace = options.namespace || this.namespace;
> this.host = options.host || this.host;
> this.headers = options.headers || this.headers;
> this.SerializerClass = options.SerializerClass || this.SerializerClass;
393c392
< _transform: function _transform(ops) {
---
> _transform: function(ops) {
395c394
< var queue = new ActionQueue['default']({ autoProcess: false });
---
> var queue = new ActionQueue['default']({autoProcess: false});
406,411c405,410
< // Not able to merge operation with previous action, so we need to
< // queue a new action.
< method = this._operationMethod(operation);
< action = this._createTransformAction(method, operation, fullResult);
< queue.push(action);
< }
---
> // Not able to merge operation with previous action, so we need to
> // queue a new action.
> method = this._operationMethod(operation);
> action = this._createTransformAction(method, operation, fullResult);
> queue.push(action);
> }
414c413
< return queue.process().then(function () {
---
> return queue.process().then(function() {
423c422
< _find: function _find(type, id, options) {
---
> _find: function(type, id, options) {
427a427
>
429a430
>
435c436
< _findLink: function _findLink(type, id, link, options) {
---
> _findLink: function(type, id, link, options) {
442,445c443,448
< return this.ajax(this.resourceLinkURL(type, id, link), 'GET').then(function (raw) {
< var relId = _this.serializer.deserializeLink(raw.data);
< return relId;
< });
---
> return this.ajax(this.resourceLinkURL(type, id, link), 'GET').then(
> function(raw) {
> var relId = _this.serializer.deserializeLink(raw.data);
> return relId;
> }
> );
448,449c451,452
< _findLinked: function _findLinked(type, id, link, options) {
< var _this = this;
---
> _findLinked: function(type, id, link, options) {
> var _this = this;
451c454
< if (options) throw new exceptions.Exception('`JSONAPISource#findLinked` does not support `options` argument');
---
> if (options) throw new exceptions.Exception('`JSONAPISource#findLinked` does not support `options` argument');
453c456
< id = this.getId(type, id);
---
> id = this.getId(type, id);
455,456c458,460
< return this.ajax(this.resourceLinkedURL(type, id, link), 'GET').then(function (raw) {
< var linkDef = _this.schema.linkDefinition(type, link);
---
> return this.ajax(this.resourceLinkedURL(type, id, link), 'GET').then(
> function(raw) {
> var linkDef = _this.schema.linkDefinition(type, link);
458c462
< var result = _this.deserialize(linkDef.model, null, raw);
---
> var result = _this.deserialize(linkDef.model, null, raw);
460,464c464,469
< return _this.transformed(result.result).then(function () {
< return result.data;
< });
< });
< },
---
> return _this.transformed(result.result).then(function() {
> return result.data;
> });
> }
> );
> },
466,467c471,472
< _query: function _query(type, query, options) {
< var _this = this;
---
> _query: function(type, query, options) {
> var _this = this;
469c474
< if (options) throw new exceptions.Exception('`JSONAPISource#query` does not support `options` argument');
---
> if (options) throw new exceptions.Exception('`JSONAPISource#query` does not support `options` argument');
471,477c476,484
< return this.ajax(this.resourceURL(type), 'GET', { data: { filter: query } }).then(function (raw) {
< var deserialized = _this.deserialize(type, null, raw);
< return _this.transformed(deserialized.result).then(function () {
< return deserialized.data;
< });
< });
< },
---
> return this.ajax(this.resourceURL(type), 'GET', {data: {filter: query}}).then(
> function(raw) {
> var deserialized = _this.deserialize(type, null, raw);
> return _this.transformed(deserialized.result).then(function() {
> return deserialized.data;
> });
> }
> );
> },
483c490
< _transformAdd: function _transformAdd(operation) {
---
> _transformAdd: function(operation) {
489,490c496,498
< return this.ajax(this.resourceURL(type), 'POST', { data: json }).then(function (raw) {
< var result = _this._transformCache(operation);
---
> return this.ajax(this.resourceURL(type), 'POST', {data: json}).then(
> function(raw) {
> var result = _this._transformCache(operation);
492,495c500,503
< var deserialized = _this.deserialize(type, id, raw);
< if (!deserialized.result.isEmpty()) {
< _this.transformed(deserialized.result);
< }
---
> var deserialized = _this.deserialize(type, id, raw);
> if (!deserialized.result.isEmpty()) {
> _this.transformed(deserialized.result);
> }
497,498c505,507
< return result;
< });
---
> return result;
> }
> );
501c510
< _transformReplace: function _transformReplace(ops) {
---
> _transformReplace: function(ops) {
511c520
< ops.forEach(function (operation) {
---
> ops.forEach(function(operation) {
530,537c539,548
< return this.ajax(this.resourceURL(type, id), 'PATCH', { data: json }).then(function (raw) {
< var result = _this._transformCache(ops);
<
< // TODO - better 204 (no content) checking
< if (raw && Object.keys(raw).length > 0) {
< var deserialized = _this.deserialize(type, id, raw);
< if (!deserialized.result.isEmpty()) {
< _this.transformed(deserialized.result);
---
> return this.ajax(this.resourceURL(type, id), 'PATCH', {data: json}).then(
> function(raw) {
> var result = _this._transformCache(ops);
>
> // TODO - better 204 (no content) checking
> if (raw && Object.keys(raw).length > 0) {
> var deserialized = _this.deserialize(type, id, raw);
> if (!deserialized.result.isEmpty()) {
> _this.transformed(deserialized.result);
> }
539d549
< }
541,542c551,553
< return result;
< });
---
> return result;
> }
> );
545c556
< _transformRemove: function _transformRemove(operation) {
---
> _transformRemove: function(operation) {
550,551c561,562
< return this.ajax(this.resourceURL(type, id), 'DELETE').then(function () {
< return _this._transformCache({ op: 'remove', path: [type, id] });
---
> return this.ajax(this.resourceURL(type, id), 'DELETE').then(function() {
> return _this._transformCache({op: 'remove', path: [type, id]});
555c566
< _transformAddLink: function _transformAddLink(operation) {
---
> _transformAddLink: function(operation) {
568,570c579,583
< return this.ajax(this.resourceLinkURL(type, id, link), method, { data: json }).then(function () {
< return _this._transformCache(operation);
< });
---
> return this.ajax(this.resourceLinkURL(type, id, link), method, {data: json}).then(
> function() {
> return _this._transformCache(operation);
> }
> );
573c586
< _transformRemoveLink: function _transformRemoveLink(operation) {
---
> _transformRemoveLink: function(operation) {
586,588c599,603
< return this.ajax(this.resourceLinkURL(type, id, link), method, { data: json }).then(function () {
< return _this._transformCache(operation);
< });
---
> return this.ajax(this.resourceLinkURL(type, id, link), method, {data: json}).then(
> function() {
> return _this._transformCache(operation);
> }
> );
591c606
< _transformReplaceLink: function _transformReplaceLink(operation) {
---
> _transformReplaceLink: function(operation) {
605c620
< data = Object.keys(relId).map(function (id) {
---
> data = Object.keys(relId).map(function(id) {
620,622c635,639
< return this.ajax(this.resourceLinkURL(type, id, link), method, { data: json }).then(function () {
< return _this._transformCache(operation);
< });
---
> return this.ajax(this.resourceLinkURL(type, id, link), method, {data: json}).then(
> function() {
> return _this._transformCache(operation);
> }
> );
625c642
< _transformReplaceAttribute: function _transformReplaceAttribute(operation) {
---
> _transformReplaceAttribute: function(operation) {
638,640c655,659
< return this.ajax(this.resourceURL(type, id), 'PATCH', { data: json }).then(function (raw) {
< return _this._transformCache(operation);
< });
---
> return this.ajax(this.resourceURL(type, id), 'PATCH', {data: json}).then(
> function(raw) {
> return _this._transformCache(operation);
> }
> );
643c662
< _operationMethod: function _operationMethod(operation) {
---
> _operationMethod: function(operation) {
658a678
>
661a682
>
663a685
>
670c692
< _mergeOperationWithAction: function _mergeOperationWithAction(action, operation) {
---
> _mergeOperationWithAction: function(action, operation) {
675c697,699
< if (actionOperation.op === 'replace' && operation.op === 'replace' && actionOperation.path[0] === operation.path[0] && actionOperation.path[1] === operation.path[1]) {
---
> if (actionOperation.op === 'replace' && operation.op === 'replace' &&
> actionOperation.path[0] === operation.path[0] &&
> actionOperation.path[1] === operation.path[1]) {
678c702
< action.data.operation = objects.toArray(action.data.operation).concat([operation]);
---
> action.data.operation = objects.toArray( action.data.operation ).concat([operation]);
684c708
< _createTransformAction: function _createTransformAction(method, operation, fullResult) {
---
> _createTransformAction: function(method, operation, fullResult) {
692,693c716,717
< process: function process() {
< return _this[this.data.method].call(_this, this.data.operation).then(function (result) {
---
> process: function() {
> return _this[this.data.method].call(_this, this.data.operation).then(function(result) {
702c726
< _findAll: function _findAll(type) {
---
> _findAll: function(type) {
704,709c728,735
< return this.ajax(this.resourceURL(type), 'GET').then(function (raw) {
< var deserialized = _this.deserialize(type, null, raw);
< return _this.transformed(deserialized.result).then(function () {
< return deserialized.data;
< });
< });
---
> return this.ajax(this.resourceURL(type), 'GET').then(
> function(raw) {
> var deserialized = _this.deserialize(type, null, raw);
> return _this.transformed(deserialized.result).then(function() {
> return deserialized.data;
> });
> }
> );
712c738
< _findOne: function _findOne(type, id) {
---
> _findOne: function(type, id) {
714,719c740,747
< return this.ajax(this.resourceURL(type, id), 'GET').then(function (raw) {
< var deserialized = _this.deserialize(type, null, raw);
< return _this.transformed(deserialized.result).then(function () {
< return deserialized.data;
< });
< });
---
> return this.ajax(this.resourceURL(type, id), 'GET').then(
> function(raw) {
> var deserialized = _this.deserialize(type, null, raw);
> return _this.transformed(deserialized.result).then(function() {
> return deserialized.data;
> });
> }
> );
722c750
< _findMany: function _findMany(type, ids) {
---
> _findMany: function(type, ids) {
724,729c752,759
< return this.ajax(this.resourceURL(type, ids), 'GET').then(function (raw) {
< var deserialized = _this.deserialize(type, null, raw);
< return _this.transformed(deserialized.result).then(function () {
< return deserialized.data;
< });
< });
---
> return this.ajax(this.resourceURL(type, ids), 'GET').then(
> function(raw) {
> var deserialized = _this.deserialize(type, null, raw);
> return _this.transformed(deserialized.result).then(function() {
> return deserialized.data;
> });
> }
> );
732c762
< _addRecordsToCache: function _addRecordsToCache(type, records) {
---
> _addRecordsToCache: function(type, records) {
735c765
< records.forEach(function (record) {
---
> records.forEach(function(record) {
742c772
< _addRecordToCache: function _addRecordToCache(type, record) {
---
> _addRecordToCache: function(type, record) {
752c782
< _transformCache: function _transformCache(ops) {
---
> _transformCache: function(ops) {
754c784
< return this._cache.transform(objects.toArray(ops));
---
> return this._cache.transform( objects.toArray(ops) );
760c790
< _resourceIdURLSegment: function _resourceIdURLSegment(type, id) {
---
> _resourceIdURLSegment: function(type, id) {
772c802
< ajax: function ajax(url, method, hash) {
---
> ajax: function(url, method, hash) {
775c805
< return new Orbit['default'].Promise(function (resolve, reject) {
---
> return new Orbit['default'].Promise(function(resolve, reject) {
802c832
< hash.success = function (json) {
---
> hash.success = function(json) {
807c837
< hash.error = function (jqXHR, textStatus, errorThrown) {
---
> hash.error = function(jqXHR, textStatus, errorThrown) {
820c850
< ajaxContentType: function ajaxContentType(url, method) {
---
> ajaxContentType: function(url, method) {
824c854
< ajaxHeaders: function ajaxHeaders() {
---
> ajaxHeaders: function() {
828c858
< resourceNamespace: function resourceNamespace(type) {
---
> resourceNamespace: function(type) {
832c862
< resourceHost: function resourceHost(type) {
---
> resourceHost: function(type) {
836c866
< resourcePath: function resourcePath(type, id) {
---
> resourcePath: function(type, id) {
844c874
< resourceURL: function resourceURL(type, id) {
---
> resourceURL: function(type, id) {
849,854c879,880
< if (host) {
< url.push(host);
< }
< if (namespace) {
< url.push(namespace);
< }
---
> if (host) { url.push(host); }
> if (namespace) { url.push(namespace); }
858,860c884
< if (!host) {
< url = '/' + url;
< }
---
> if (!host) { url = '/' + url; }
865c889
< resourceLinkURL: function resourceLinkURL(type, id, link, relId) {
---
> resourceLinkURL: function(type, id, link, relId) {
878c902
< resourceLinkedURL: function resourceLinkedURL(type, id, link) {
---
> resourceLinkedURL: function(type, id, link) {
884c908
< deserialize: function deserialize(type, id, data) {
---
> deserialize: function(type, id, data) {
897c921
< Object.keys(records.included).forEach(function (relType) {
---
> Object.keys(records.included).forEach(function(relType) {
908a933
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment