diff --git a/README.md b/README.md index 96922097..293f07bd 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,6 @@ # mobx-async-store Mobx-based store for async data fetching and state management. https://artemis-ag.github.io/mobx-async-store/ - -# Caution - -This library is experimental and not advised for use in production use. - -# TODO - -- [ ] Improve documentation - ## Table of Contents - Introduction diff --git a/dist/mobx-async-store.cjs.js b/dist/mobx-async-store.cjs.js index 253ba58e..db94291a 100644 --- a/dist/mobx-async-store.cjs.js +++ b/dist/mobx-async-store.cjs.js @@ -2,11 +2,11 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator'); var _initializerDefineProperty = require('@babel/runtime/helpers/initializerDefineProperty'); var _classCallCheck = require('@babel/runtime/helpers/classCallCheck'); var _createClass = require('@babel/runtime/helpers/createClass'); +var _defineProperty = require('@babel/runtime/helpers/defineProperty'); require('@babel/runtime/helpers/initializerWarningHelper'); var _applyDecoratedDescriptor = require('@babel/runtime/helpers/applyDecoratedDescriptor'); var _typeof = require('@babel/runtime/helpers/typeof'); @@ -33,11 +33,11 @@ var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } -var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator); var _initializerDefineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_initializerDefineProperty); var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck); var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); +var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var _applyDecoratedDescriptor__default = /*#__PURE__*/_interopDefaultLegacy(_applyDecoratedDescriptor); var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime); @@ -315,8 +315,9 @@ var Schema = /*#__PURE__*/function () { function Schema() { _classCallCheck__default['default'](this, Schema); - this.structure = {}; - this.relations = {}; + _defineProperty__default['default'](this, "structure", {}); + + _defineProperty__default['default'](this, "relations", {}); } _createClass__default['default'](Schema, [{ @@ -449,13 +450,15 @@ var Model = (_class$1 = /*#__PURE__*/function () { _classCallCheck__default['default'](this, Model); - this.isInFlight = false; + _defineProperty__default['default'](this, "isInFlight", false); _initializerDefineProperty__default['default'](this, "errors", _descriptor$1, this); - this._snapshots = []; + _defineProperty__default['default'](this, "_snapshots", []); - this._makeObservable(initialAttributes); + mobx.makeObservable(this); + var defaultAttributes = this.defaultAttributes; + mobx.extendObservable(this, _objectSpread$2(_objectSpread$2({}, defaultAttributes), initialAttributes)); this._takeSnapshot({ persisted: !this.isNew @@ -889,19 +892,6 @@ var Model = (_class$1 = /*#__PURE__*/function () { } /* Private Methods */ - /** - * Magic method that makes changes to records - * observable - * - * @method _makeObservable - */ - - }, { - key: "_makeObservable", - value: function _makeObservable(initialAttributes) { - var defaultAttributes = this.defaultAttributes; - mobx.extendObservable(this, _objectSpread$2(_objectSpread$2({}, defaultAttributes), initialAttributes)); - } /** * The current state of defined attributes and relationships of the instance * Really just an alias for attributes @@ -1363,22 +1353,22 @@ var Store = (_class = /*#__PURE__*/function () { _initializerDefineProperty__default['default'](this, "lastResponseHeaders", _descriptor2, this); - this.genericErrorMessage = 'Something went wrong.'; + _defineProperty__default['default'](this, "genericErrorMessage", 'Something went wrong.'); - this.add = function (type, data) { + _defineProperty__default['default'](this, "add", function (type, data) { if (data.constructor.name === 'Array') { return _this.addModels(type, data); } else { return _this.addModel(type, mobx.toJS(data)); } - }; + }); - this.pickAttributes = function (properties, type) { + _defineProperty__default['default'](this, "pickAttributes", function (properties, type) { var attributeNames = Object.keys(_this.schema.structure[type]); return pick__default['default'](properties, attributeNames); - }; + }); - this.pickRelationships = function (properties, type) { + _defineProperty__default['default'](this, "pickRelationships", function (properties, type) { var relationshipNames = Object.keys(_this.schema.relations[type] || {}); var allRelationships = pick__default['default'](properties, relationshipNames); return Object.keys(allRelationships).reduce(function (references, key) { @@ -1404,9 +1394,9 @@ var Store = (_class = /*#__PURE__*/function () { }; return references; }, {}); - }; + }); - this.build = function (type, properties) { + _defineProperty__default['default'](this, "build", function (type, properties) { var id = idOrNewId(properties.id); var attributes = _this.pickAttributes(properties, type); @@ -1416,19 +1406,19 @@ var Store = (_class = /*#__PURE__*/function () { }); return model; - }; + }); _initializerDefineProperty__default['default'](this, "addModel", _descriptor3, this); - this.addModels = function (type, data) { + _defineProperty__default['default'](this, "addModels", function (type, data) { return mobx.transaction(function () { return data.map(function (obj) { return _this.addModel(type, obj); }); }); - }; + }); - this.bulkSave = /*#__PURE__*/function () { + _defineProperty__default['default'](this, "bulkSave", /*#__PURE__*/function () { var _ref = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(type, records) { var options, queryParams, @@ -1479,11 +1469,11 @@ var Store = (_class = /*#__PURE__*/function () { return function (_x2, _x3) { return _ref.apply(this, arguments); }; - }(); + }()); _initializerDefineProperty__default['default'](this, "remove", _descriptor4, this); - this.getOne = function (type, id) { + _defineProperty__default['default'](this, "getOne", function (type, id) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!id) { @@ -1498,9 +1488,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.getRecord(type, id); } - }; + }); - this.findOne = function (type, id) { + _defineProperty__default['default'](this, "findOne", function (type, id) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!id) { @@ -1515,9 +1505,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.fetchOne(type, id, options); } - }; + }); - this.getMany = function (type, ids) { + _defineProperty__default['default'](this, "getMany", function (type, ids) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var idsToQuery = ids.slice().map(String); @@ -1526,9 +1516,9 @@ var Store = (_class = /*#__PURE__*/function () { return records.filter(function (record) { return idsToQuery.includes(record.id); }); - }; + }); - this.fetchMany = function (type, ids) { + _defineProperty__default['default'](this, "fetchMany", function (type, ids) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var idsToQuery = ids.slice().map(String); var queryParams = options.queryParams || {}; @@ -1550,9 +1540,9 @@ var Store = (_class = /*#__PURE__*/function () { }).catch(function (err) { return Promise.reject(err); }); - }; + }); - this.findMany = function (type, ids) { + _defineProperty__default['default'](this, "findMany", function (type, ids) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var idsToQuery = ids.slice().map(String); @@ -1586,9 +1576,9 @@ var Store = (_class = /*#__PURE__*/function () { return query.then(function (recordsFromServer) { return recordsInStore.concat.apply(recordsInStore, _toConsumableArray__default['default'](recordsFromServer)); }); - }; + }); - this.getAll = function (type) { + _defineProperty__default['default'](this, "getAll", function (type) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var queryParams = options.queryParams; @@ -1597,9 +1587,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.getRecords(type); } - }; + }); - this.findAll = function (type) { + _defineProperty__default['default'](this, "findAll", function (type) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var records = _this.getAll(type, options); @@ -1609,8 +1599,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.fetchAll(type, options); } - }; + }); + mobx.makeObservable(this); this.init(_options); this.schema = schema; } @@ -2490,7 +2481,7 @@ var Store = (_class = /*#__PURE__*/function () { _this9.data[type].records.delete(String(id)); }; } -})), _class); +}), _applyDecoratedDescriptor__default['default'](_class.prototype, "initializeObservableDataProperty", [mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, "initializeObservableDataProperty"), _class.prototype)), _class); /** * returns `true` as long as the `value` is not `null`, `undefined`, or `''` @@ -2840,7 +2831,7 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { _this = _super.call.apply(_super, [this].concat(_toConsumableArray__default['default'](_array))); - _this.add = function (relatedRecord) { + _defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "add", function (relatedRecord) { var _assertThisInitialize = _assertThisInitialized__default['default'](_this), record = _assertThisInitialize.record, property = _assertThisInitialize.property; @@ -2885,9 +2876,9 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { } return relatedRecord; - }; + }); - _this.remove = function (relatedRecord) { + _defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "remove", function (relatedRecord) { var _assertThisInitialize2 = _assertThisInitialized__default['default'](_this), record = _assertThisInitialize2.record, property = _assertThisInitialize2.property; @@ -2914,10 +2905,6 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { if (!relationships[property].data.length) { delete relationships[property]; - } - - if (!Object.keys(record.relationships).length) { - delete record.relationships; } // hack this will only work with singularized relationships. @@ -2925,9 +2912,9 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { } return relatedRecord; - }; + }); - _this.replace = function (array) { + _defineProperty__default['default'](_assertThisInitialized__default['default'](_this), "replace", function (array) { var _assertThisInitialize3 = _assertThisInitialized__default['default'](_this), record = _assertThisInitialize3.record, property = _assertThisInitialize3.property; @@ -2941,7 +2928,7 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { return _this.add(object); }); }); - }; + }); _this.property = _property; _this.record = _record; diff --git a/dist/mobx-async-store.esm.js b/dist/mobx-async-store.esm.js index 770e7697..9ae0fce4 100644 --- a/dist/mobx-async-store.esm.js +++ b/dist/mobx-async-store.esm.js @@ -1,13 +1,13 @@ -import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; import _initializerDefineProperty from '@babel/runtime/helpers/initializerDefineProperty'; import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; import _createClass from '@babel/runtime/helpers/createClass'; +import _defineProperty from '@babel/runtime/helpers/defineProperty'; import '@babel/runtime/helpers/initializerWarningHelper'; import _applyDecoratedDescriptor from '@babel/runtime/helpers/applyDecoratedDescriptor'; import _typeof from '@babel/runtime/helpers/typeof'; import _regeneratorRuntime from '@babel/runtime/regenerator'; -import { computed, observable, set, extendObservable, toJS, transaction, action } from 'mobx'; +import { computed, observable, set, toJS, transaction, makeObservable, extendObservable, action } from 'mobx'; import _inherits from '@babel/runtime/helpers/inherits'; import _setPrototypeOf from '@babel/runtime/helpers/setPrototypeOf'; import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; @@ -283,8 +283,9 @@ var Schema = /*#__PURE__*/function () { function Schema() { _classCallCheck(this, Schema); - this.structure = {}; - this.relations = {}; + _defineProperty(this, "structure", {}); + + _defineProperty(this, "relations", {}); } _createClass(Schema, [{ @@ -417,13 +418,15 @@ var Model = (_class$1 = /*#__PURE__*/function () { _classCallCheck(this, Model); - this.isInFlight = false; + _defineProperty(this, "isInFlight", false); _initializerDefineProperty(this, "errors", _descriptor$1, this); - this._snapshots = []; + _defineProperty(this, "_snapshots", []); - this._makeObservable(initialAttributes); + makeObservable(this); + var defaultAttributes = this.defaultAttributes; + extendObservable(this, _objectSpread$2(_objectSpread$2({}, defaultAttributes), initialAttributes)); this._takeSnapshot({ persisted: !this.isNew @@ -857,19 +860,6 @@ var Model = (_class$1 = /*#__PURE__*/function () { } /* Private Methods */ - /** - * Magic method that makes changes to records - * observable - * - * @method _makeObservable - */ - - }, { - key: "_makeObservable", - value: function _makeObservable(initialAttributes) { - var defaultAttributes = this.defaultAttributes; - extendObservable(this, _objectSpread$2(_objectSpread$2({}, defaultAttributes), initialAttributes)); - } /** * The current state of defined attributes and relationships of the instance * Really just an alias for attributes @@ -1331,22 +1321,22 @@ var Store = (_class = /*#__PURE__*/function () { _initializerDefineProperty(this, "lastResponseHeaders", _descriptor2, this); - this.genericErrorMessage = 'Something went wrong.'; + _defineProperty(this, "genericErrorMessage", 'Something went wrong.'); - this.add = function (type, data) { + _defineProperty(this, "add", function (type, data) { if (data.constructor.name === 'Array') { return _this.addModels(type, data); } else { return _this.addModel(type, toJS(data)); } - }; + }); - this.pickAttributes = function (properties, type) { + _defineProperty(this, "pickAttributes", function (properties, type) { var attributeNames = Object.keys(_this.schema.structure[type]); return pick(properties, attributeNames); - }; + }); - this.pickRelationships = function (properties, type) { + _defineProperty(this, "pickRelationships", function (properties, type) { var relationshipNames = Object.keys(_this.schema.relations[type] || {}); var allRelationships = pick(properties, relationshipNames); return Object.keys(allRelationships).reduce(function (references, key) { @@ -1372,9 +1362,9 @@ var Store = (_class = /*#__PURE__*/function () { }; return references; }, {}); - }; + }); - this.build = function (type, properties) { + _defineProperty(this, "build", function (type, properties) { var id = idOrNewId(properties.id); var attributes = _this.pickAttributes(properties, type); @@ -1384,19 +1374,19 @@ var Store = (_class = /*#__PURE__*/function () { }); return model; - }; + }); _initializerDefineProperty(this, "addModel", _descriptor3, this); - this.addModels = function (type, data) { + _defineProperty(this, "addModels", function (type, data) { return transaction(function () { return data.map(function (obj) { return _this.addModel(type, obj); }); }); - }; + }); - this.bulkSave = /*#__PURE__*/function () { + _defineProperty(this, "bulkSave", /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(type, records) { var options, queryParams, @@ -1447,11 +1437,11 @@ var Store = (_class = /*#__PURE__*/function () { return function (_x2, _x3) { return _ref.apply(this, arguments); }; - }(); + }()); _initializerDefineProperty(this, "remove", _descriptor4, this); - this.getOne = function (type, id) { + _defineProperty(this, "getOne", function (type, id) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!id) { @@ -1466,9 +1456,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.getRecord(type, id); } - }; + }); - this.findOne = function (type, id) { + _defineProperty(this, "findOne", function (type, id) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!id) { @@ -1483,9 +1473,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.fetchOne(type, id, options); } - }; + }); - this.getMany = function (type, ids) { + _defineProperty(this, "getMany", function (type, ids) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var idsToQuery = ids.slice().map(String); @@ -1494,9 +1484,9 @@ var Store = (_class = /*#__PURE__*/function () { return records.filter(function (record) { return idsToQuery.includes(record.id); }); - }; + }); - this.fetchMany = function (type, ids) { + _defineProperty(this, "fetchMany", function (type, ids) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var idsToQuery = ids.slice().map(String); var queryParams = options.queryParams || {}; @@ -1518,9 +1508,9 @@ var Store = (_class = /*#__PURE__*/function () { }).catch(function (err) { return Promise.reject(err); }); - }; + }); - this.findMany = function (type, ids) { + _defineProperty(this, "findMany", function (type, ids) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var idsToQuery = ids.slice().map(String); @@ -1554,9 +1544,9 @@ var Store = (_class = /*#__PURE__*/function () { return query.then(function (recordsFromServer) { return recordsInStore.concat.apply(recordsInStore, _toConsumableArray(recordsFromServer)); }); - }; + }); - this.getAll = function (type) { + _defineProperty(this, "getAll", function (type) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var queryParams = options.queryParams; @@ -1565,9 +1555,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.getRecords(type); } - }; + }); - this.findAll = function (type) { + _defineProperty(this, "findAll", function (type) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var records = _this.getAll(type, options); @@ -1577,8 +1567,9 @@ var Store = (_class = /*#__PURE__*/function () { } else { return _this.fetchAll(type, options); } - }; + }); + makeObservable(this); this.init(_options); this.schema = schema; } @@ -2458,7 +2449,7 @@ var Store = (_class = /*#__PURE__*/function () { _this9.data[type].records.delete(String(id)); }; } -})), _class); +}), _applyDecoratedDescriptor(_class.prototype, "initializeObservableDataProperty", [action], Object.getOwnPropertyDescriptor(_class.prototype, "initializeObservableDataProperty"), _class.prototype)), _class); /** * returns `true` as long as the `value` is not `null`, `undefined`, or `''` @@ -2808,7 +2799,7 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { _this = _super.call.apply(_super, [this].concat(_toConsumableArray(_array))); - _this.add = function (relatedRecord) { + _defineProperty(_assertThisInitialized(_this), "add", function (relatedRecord) { var _assertThisInitialize = _assertThisInitialized(_this), record = _assertThisInitialize.record, property = _assertThisInitialize.property; @@ -2853,9 +2844,9 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { } return relatedRecord; - }; + }); - _this.remove = function (relatedRecord) { + _defineProperty(_assertThisInitialized(_this), "remove", function (relatedRecord) { var _assertThisInitialize2 = _assertThisInitialized(_this), record = _assertThisInitialize2.record, property = _assertThisInitialize2.property; @@ -2882,10 +2873,6 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { if (!relationships[property].data.length) { delete relationships[property]; - } - - if (!Object.keys(record.relationships).length) { - delete record.relationships; } // hack this will only work with singularized relationships. @@ -2893,9 +2880,9 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { } return relatedRecord; - }; + }); - _this.replace = function (array) { + _defineProperty(_assertThisInitialized(_this), "replace", function (array) { var _assertThisInitialize3 = _assertThisInitialized(_this), record = _assertThisInitialize3.record, property = _assertThisInitialize3.property; @@ -2909,7 +2896,7 @@ var RelatedRecordsArray = /*#__PURE__*/function (_Array) { return _this.add(object); }); }); - }; + }); _this.property = _property; _this.record = _record; diff --git a/docs/classes/Model.html b/docs/classes/Model.html index e16f1115..6845b48d 100644 --- a/docs/classes/Model.html +++ b/docs/classes/Model.html @@ -17,7 +17,7 @@

- API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
@@ -84,7 +84,7 @@

Model Class

- Defined in: src/Model.js:79 + Defined in: src/Model.js:80
@@ -115,10 +115,6 @@

Methods

  • _applySnapshot -
  • -
  • - _makeObservable -
  • _takeSnapshot @@ -295,7 +291,7 @@

    _applySnapshot

    Defined in - src/Model.js:553 + src/Model.js:546

    @@ -327,38 +323,6 @@

    Parameters:

    -
    -
    -

    _makeObservable

    - - () - - - - - - - - -
    -

    - Defined in - src/Model.js:466 -

    - - - -
    - -
    -

    Magic method that makes changes to records -observable

    - -
    - - - -

    _takeSnapshot

    @@ -381,7 +345,7 @@

    _takeSnapshot

    Defined in - src/Model.js:532 + src/Model.js:525

    @@ -433,7 +397,7 @@

    attributeDefinitions

    Defined in - src/Model.js:598 + src/Model.js:591

    @@ -474,7 +438,7 @@

    attributeNames

    Defined in - src/Model.js:640 + src/Model.js:633

    @@ -515,7 +479,7 @@

    attributes

    Defined in - src/Model.js:580 + src/Model.js:573

    @@ -555,7 +519,7 @@

    constructor

    Defined in - src/Model.js:83 + src/Model.js:84

    @@ -589,7 +553,7 @@

    defaultAttributes

    Defined in - src/Model.js:660 + src/Model.js:653

    @@ -630,7 +594,7 @@

    destroy

    Defined in - src/Model.js:399 + src/Model.js:407

    @@ -673,7 +637,7 @@

    dirtyAttributes

    Defined in - src/Model.js:143 + src/Model.js:151

    @@ -725,7 +689,7 @@

    dirtyRelationships

    Defined in - src/Model.js:176 + src/Model.js:184

    @@ -775,7 +739,7 @@

    hasErrors

    Defined in - src/Model.js:620 + src/Model.js:613

    @@ -816,7 +780,7 @@

    hasErrors

    Defined in - src/Model.js:630 + src/Model.js:623

    @@ -863,7 +827,7 @@

    isSame

    Defined in - src/Model.js:805 + src/Model.js:798

    @@ -922,7 +886,7 @@

    jsonapi

    Defined in - src/Model.js:677 + src/Model.js:670

    @@ -963,7 +927,7 @@

    previousSnapshot

    Defined in - src/Model.js:512 + src/Model.js:505

    @@ -994,7 +958,7 @@

    previousSnapshot

    Defined in - src/Model.js:523 + src/Model.js:516

    @@ -1028,7 +992,7 @@

    relationshipDefinitions

    Defined in - src/Model.js:609 + src/Model.js:602

    @@ -1069,7 +1033,7 @@

    relationshipNames

    Defined in - src/Model.js:650 + src/Model.js:643

    @@ -1116,7 +1080,7 @@

    reload

    Defined in - src/Model.js:355 + src/Model.js:363

    @@ -1170,7 +1134,7 @@

    rollback

    Defined in - src/Model.js:274 + src/Model.js:282

    @@ -1209,7 +1173,7 @@

    rollbackToPersisted

    Defined in - src/Model.js:291 + src/Model.js:299

    @@ -1250,7 +1214,7 @@

    save

    Defined in - src/Model.js:301 + src/Model.js:309

    @@ -1304,7 +1268,7 @@

    setPreviousSnapshot

    Defined in - src/Model.js:503 + src/Model.js:496

    @@ -1338,7 +1302,7 @@

    snapshot

    Defined in - src/Model.js:481 + src/Model.js:474

    @@ -1390,7 +1354,7 @@

    type

    Defined in - src/Model.js:570 + src/Model.js:563

    @@ -1439,7 +1403,7 @@

    validate

    Defined in - src/Model.js:375 + src/Model.js:383

    @@ -1513,7 +1477,7 @@

    validateProperties

    Defined in - src/Model.js:18 + src/Model.js:19

    @@ -1594,7 +1558,7 @@

    endpoint

    Defined in - src/Model.js:101 + src/Model.js:109

    @@ -1620,7 +1584,7 @@

    errors

    Defined in - src/Model.js:252 + src/Model.js:260

    @@ -1650,7 +1614,7 @@

    hasUnpersistedChanges

    Defined in - src/Model.js:214 + src/Model.js:222

    @@ -1675,7 +1639,7 @@

    isDirty

    Defined in - src/Model.js:108 + src/Model.js:116

    @@ -1721,7 +1685,7 @@

    isInFlight

    Defined in - src/Model.js:235 + src/Model.js:243

    @@ -1755,7 +1719,7 @@

    isNew

    Defined in - src/Model.js:223 + src/Model.js:231

    @@ -1780,7 +1744,7 @@

    snapshots

    Defined in - src/Model.js:265 + src/Model.js:273

    @@ -1807,7 +1771,7 @@

    type

    Defined in - src/Model.js:93 + src/Model.js:101

    diff --git a/docs/classes/RelatedRecordsArray.html b/docs/classes/RelatedRecordsArray.html index b4874fcb..1dcf69de 100644 --- a/docs/classes/RelatedRecordsArray.html +++ b/docs/classes/RelatedRecordsArray.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    diff --git a/docs/classes/Schema.html b/docs/classes/Schema.html index b1641c3e..982d883a 100644 --- a/docs/classes/Schema.html +++ b/docs/classes/Schema.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    diff --git a/docs/classes/Store.html b/docs/classes/Store.html index e2769550..bc1e4206 100644 --- a/docs/classes/Store.html +++ b/docs/classes/Store.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    @@ -349,7 +349,7 @@

    add

    Defined in - src/Store.js:53 + src/Store.js:54

    @@ -433,7 +433,7 @@

    addModel

    Defined in - src/Store.js:155 + src/Store.js:156

    @@ -511,7 +511,7 @@

    addModels

    Defined in - src/Store.js:176 + src/Store.js:177

    @@ -589,7 +589,7 @@

    build

    Defined in - src/Store.js:132 + src/Store.js:133

    @@ -674,7 +674,7 @@

    bulkSave

    Defined in - src/Store.js:186 + src/Store.js:187

    @@ -789,7 +789,7 @@

    createModel

    Defined in - src/Store.js:848 + src/Store.js:850

    @@ -871,7 +871,7 @@

    createModelsFromData

    Defined in - src/Store.js:826 + src/Store.js:828

    @@ -924,7 +924,7 @@

    createOrUpdateModel

    Defined in - src/Store.js:786 + src/Store.js:788

    @@ -980,7 +980,7 @@

    fetch

    Defined in - src/Store.js:619 + src/Store.js:621

    @@ -1050,7 +1050,7 @@

    fetchAll

    Defined in - src/Store.js:453 + src/Store.js:454

    @@ -1132,7 +1132,7 @@

    fetchMany

    Defined in - src/Store.js:346 + src/Store.js:347

    @@ -1227,7 +1227,7 @@

    fetchOne

    Defined in - src/Store.js:263 + src/Store.js:264

    @@ -1315,7 +1315,7 @@

    fetchUrl

    Defined in - src/Store.js:422 + src/Store.js:423

    @@ -1385,7 +1385,7 @@

    findAll

    Defined in - src/Store.js:490 + src/Store.js:491

    @@ -1492,7 +1492,7 @@

    findMany

    Defined in - src/Store.js:372 + src/Store.js:373

    @@ -1595,7 +1595,7 @@

    findOne

    Defined in - src/Store.js:300 + src/Store.js:301

    @@ -1693,7 +1693,7 @@

    getAll

    Defined in - src/Store.js:436 + src/Store.js:437

    @@ -1772,7 +1772,7 @@

    getCachedId

    Defined in - src/Store.js:763 + src/Store.js:765

    @@ -1850,7 +1850,7 @@

    getCachedIds

    Defined in - src/Store.js:748 + src/Store.js:750

    @@ -1931,7 +1931,7 @@

    getCachedRecord

    Defined in - src/Store.js:715 + src/Store.js:717

    @@ -2022,7 +2022,7 @@

    getCachedRecords

    Defined in - src/Store.js:730 + src/Store.js:732

    @@ -2109,7 +2109,7 @@

    getKlass

    Defined in - src/Store.js:775 + src/Store.js:777

    @@ -2180,7 +2180,7 @@

    getMany

    Defined in - src/Store.js:330 + src/Store.js:331

    @@ -2274,7 +2274,7 @@

    getOne

    Defined in - src/Store.js:240 + src/Store.js:241

    @@ -2366,7 +2366,7 @@

    getRecord

    Defined in - src/Store.js:658 + src/Store.js:660

    @@ -2441,7 +2441,7 @@

    getRecords

    Defined in - src/Store.js:678 + src/Store.js:680

    @@ -2515,7 +2515,7 @@

    getRecordsById

    Defined in - src/Store.js:699 + src/Store.js:701

    @@ -2590,7 +2590,7 @@

    getType

    Defined in - src/Store.js:647 + src/Store.js:649

    @@ -2652,7 +2652,7 @@

    init

    Defined in - src/Store.js:560 + src/Store.js:561

    @@ -2706,7 +2706,7 @@

    initializeNetworkConfiguration

    Defined in - src/Store.js:572 + src/Store.js:573

    @@ -2760,7 +2760,7 @@

    initializeNetworkConfiguration

    Defined in - src/Store.js:584 + src/Store.js:585

    @@ -2808,7 +2808,7 @@

    initializeObservableDataProperty

    Defined in - src/Store.js:598 + src/Store.js:599

    @@ -2853,7 +2853,7 @@

    pickAttributes

    Defined in - src/Store.js:74 + src/Store.js:75

    @@ -2934,7 +2934,7 @@

    pickRelationships

    Defined in - src/Store.js:92 + src/Store.js:93

    @@ -3019,7 +3019,7 @@

    remove

    Defined in - src/Store.js:226 + src/Store.js:227

    @@ -3079,7 +3079,7 @@

    reset

    Defined in - src/Store.js:537 + src/Store.js:538

    @@ -3123,7 +3123,7 @@

    updateRecords

    Defined in - src/Store.js:869 + src/Store.js:871

    diff --git a/docs/data.json b/docs/data.json index a671d00c..374d1691 100644 --- a/docs/data.json +++ b/docs/data.json @@ -3,7 +3,7 @@ "name": "mobx-async-store", "description": "Asyc Data Store for mobx", "url": "https://github.com/artemis-ag/mobx-async-store", - "version": "3.10.3" + "version": "4.0.0-rc.1" }, "files": { "src/decorators/attributes.js": { @@ -98,7 +98,7 @@ "plugin_for": [], "extension_for": [], "file": "src/Model.js", - "line": 79 + "line": 80 }, "Store": { "name": "Store", @@ -295,7 +295,7 @@ }, { "file": "src/Model.js", - "line": 18, + "line": 19, "description": "Maps the passed-in property names through and runs validations against those properties", "itemtype": "method", "name": "validateProperties", @@ -324,7 +324,7 @@ }, { "file": "src/Model.js", - "line": 83, + "line": 84, "description": "Initializer for model", "itemtype": "method", "name": "constructor", @@ -332,7 +332,7 @@ }, { "file": "src/Model.js", - "line": 93, + "line": 101, "description": "The type of the model. Defined on the class. Defaults to the underscored version of the class name\n(eg 'calendar_events').", "itemtype": "property", "name": "type", @@ -341,7 +341,7 @@ }, { "file": "src/Model.js", - "line": 101, + "line": 109, "description": "The canonical path to the resource on the server. Defined on the class.\nDefaults to the underscored version of the class name", "itemtype": "property", "name": "endpoint", @@ -350,7 +350,7 @@ }, { "file": "src/Model.js", - "line": 108, + "line": 116, "description": "True if the instance has been modified from its persisted state\n\nNOTE that isDirty does _NOT_ track changes to the related objects\nbut it _does_ track changes to the relationships themselves.\n\nFor example, adding or removing a related object will mark this record as dirty,\nbut changing a related object's properties will not mark this record as dirty.\n\nThe caller is reponsible for asking related objects about their\nown dirty state.\n\n```\nkpi = store.add('kpis', { name: 'A good thing to measure' })\nkpi.isDirty\n=> true\nkpi.name\n=> \"A good thing to measure\"\nawait kpi.save()\nkpi.isDirty\n=> false\nkpi.name = \"Another good thing to measure\"\nkpi.isDirty\n=> true\nawait kpi.save()\nkpi.isDirty\n=> false\n```", "itemtype": "property", "name": "isDirty", @@ -359,7 +359,7 @@ }, { "file": "src/Model.js", - "line": 143, + "line": 151, "description": "A list of any attribute paths which have been changed since the previous snapshot\n\nconst todo = new Todo({ title: 'Buy Milk' })\ntodo.dirtyAttributes\n=> []\ntodo.title = 'Buy Cheese'\ntodo.dirtyAttributes\n=> ['title']\ntodo.options = { variety: 'Cheddar' }\ntodo.dirtyAttributes\n=> ['title', 'options.variety']", "itemtype": "method", "name": "dirtyAttributes", @@ -371,7 +371,7 @@ }, { "file": "src/Model.js", - "line": 176, + "line": 184, "description": "A list of any relationship paths which have been changed since the previous snapshot\nWe check changes to both ids and types in case there are polymorphic relationships\n\nconst todo = new Todo({ title: 'Buy Milk' })\ntodo.dirtyRelationships\n=> []\ntodo.note = note1\ntodo.dirtyRelationships\n=> ['relationships.note']", "itemtype": "method", "name": "dirtyRelationships", @@ -383,7 +383,7 @@ }, { "file": "src/Model.js", - "line": 214, + "line": 222, "description": "Have any changes been made since this record was last persisted?", "itemtype": "property", "name": "hasUnpersistedChanges", @@ -392,7 +392,7 @@ }, { "file": "src/Model.js", - "line": 223, + "line": 231, "description": "True if the model has not been sent to the store", "itemtype": "property", "name": "isNew", @@ -401,7 +401,7 @@ }, { "file": "src/Model.js", - "line": 235, + "line": 243, "description": "True if the instance is coming from / going to the server\n```\nkpi = store.find('kpis', 5)\n// fetch started\nkpi.isInFlight\n=> true\n// fetch finished\nkpi.isInFlight\n=> false\n```", "itemtype": "property", "name": "isInFlight", @@ -411,7 +411,7 @@ }, { "file": "src/Model.js", - "line": 252, + "line": 260, "description": "A hash of errors from the server\n```\nkpi = store.find('kpis', 5)\nkpi.errors\n=> { authorization: \"You do not have access to this resource\" }\n```", "itemtype": "property", "name": "errors", @@ -421,7 +421,7 @@ }, { "file": "src/Model.js", - "line": 265, + "line": 273, "description": "a list of snapshots that have been taken since the record was either last persisted or since it was instantiated", "itemtype": "property", "name": "snapshots", @@ -431,7 +431,7 @@ }, { "file": "src/Model.js", - "line": 274, + "line": 282, "description": "restores data to its last snapshot state\n```\nkpi = store.find('kpis', 5)\nkpi.name\n=> \"A good thing to measure\"\nkpi.name = \"Another good thing to measure\"\nkpi.rollback()\nkpi.name\n=> \"A good thing to measure\"\n```", "itemtype": "method", "name": "rollback", @@ -439,7 +439,7 @@ }, { "file": "src/Model.js", - "line": 291, + "line": 299, "description": "restores data to its last persisted state or the oldest snapshot\nstate if the model was never persisted", "itemtype": "method", "name": "rollbackToPersisted", @@ -447,7 +447,7 @@ }, { "file": "src/Model.js", - "line": 301, + "line": 309, "description": "creates or updates a record.", "itemtype": "method", "name": "save", @@ -466,7 +466,7 @@ }, { "file": "src/Model.js", - "line": 355, + "line": 363, "description": "Replaces the record with the canonical version from the server.", "itemtype": "method", "name": "reload", @@ -485,7 +485,7 @@ }, { "file": "src/Model.js", - "line": 375, + "line": 383, "description": "Checks all validations, adding errors where necessary and returning `false` if any are not valid\nDefault is to check all validations, but they can be selectively run via options:\n - attributes - an array of names of attributes to validate\n - relationships - an array of names of relationships to validate", "itemtype": "method", "name": "validate", @@ -504,7 +504,7 @@ }, { "file": "src/Model.js", - "line": 399, + "line": 407, "description": "deletes a record from the store and server", "itemtype": "method", "name": "destroy", @@ -516,15 +516,7 @@ }, { "file": "src/Model.js", - "line": 466, - "description": "Magic method that makes changes to records\nobservable", - "itemtype": "method", - "name": "_makeObservable", - "class": "Model" - }, - { - "file": "src/Model.js", - "line": 481, + "line": 474, "description": "The current state of defined attributes and relationships of the instance\nReally just an alias for attributes\n```\ntodo = store.find('todos', 5)\ntodo.title\n=> \"Buy the eggs\"\nsnapshot = todo.snapshot\ntodo.title = \"Buy the eggs and bacon\"\nsnapshot.title\n=> \"Buy the eggs and bacon\"\n```", "itemtype": "method", "name": "snapshot", @@ -536,7 +528,7 @@ }, { "file": "src/Model.js", - "line": 503, + "line": 496, "description": "Sets previous snapshot to current snapshot", "itemtype": "method", "name": "setPreviousSnapshot", @@ -544,7 +536,7 @@ }, { "file": "src/Model.js", - "line": 512, + "line": 505, "description": "the latest snapshot", "itemtype": "method", "name": "previousSnapshot", @@ -552,7 +544,7 @@ }, { "file": "src/Model.js", - "line": 523, + "line": 516, "description": "the latest persisted snapshot or the first snapshot if the model was never persisted", "itemtype": "method", "name": "previousSnapshot", @@ -560,7 +552,7 @@ }, { "file": "src/Model.js", - "line": 532, + "line": 525, "description": "take a snapshot of the current model state.\nif persisted, clear the stack and push this snapshot to the top\nif not persisted, push this snapshot to the top of the stack", "itemtype": "method", "name": "_takeSnapshot", @@ -575,7 +567,7 @@ }, { "file": "src/Model.js", - "line": 553, + "line": 546, "description": "set the current attributes and relationships to the attributes\nand relationships of the snapshot to be applied. also reset errors", "itemtype": "method", "name": "_applySnapshot", @@ -590,7 +582,7 @@ }, { "file": "src/Model.js", - "line": 570, + "line": 563, "description": "shortcut to get the static", "itemtype": "method", "name": "type", @@ -602,7 +594,7 @@ }, { "file": "src/Model.js", - "line": 580, + "line": 573, "description": "current attributes of record", "itemtype": "method", "name": "attributes", @@ -614,7 +606,7 @@ }, { "file": "src/Model.js", - "line": 598, + "line": 591, "description": "Getter find the attribute definition for the model type.", "itemtype": "method", "name": "attributeDefinitions", @@ -626,7 +618,7 @@ }, { "file": "src/Model.js", - "line": 609, + "line": 602, "description": "Getter find the relationship definitions for the model type.", "itemtype": "method", "name": "relationshipDefinitions", @@ -638,7 +630,7 @@ }, { "file": "src/Model.js", - "line": 620, + "line": 613, "description": "Getter to check if the record has errors.", "itemtype": "method", "name": "hasErrors", @@ -650,7 +642,7 @@ }, { "file": "src/Model.js", - "line": 630, + "line": 623, "description": "Getter to check if the record has errors.", "itemtype": "method", "name": "hasErrors", @@ -662,7 +654,7 @@ }, { "file": "src/Model.js", - "line": 640, + "line": 633, "description": "Getter to just get the names of a records attributes.", "itemtype": "method", "name": "attributeNames", @@ -674,7 +666,7 @@ }, { "file": "src/Model.js", - "line": 650, + "line": 643, "description": "Getter to just get the names of a records relationships.", "itemtype": "method", "name": "relationshipNames", @@ -686,7 +678,7 @@ }, { "file": "src/Model.js", - "line": 660, + "line": 653, "description": "getter method to get the default attributes", "itemtype": "method", "name": "defaultAttributes", @@ -698,7 +690,7 @@ }, { "file": "src/Model.js", - "line": 677, + "line": 670, "description": "getter method to get data in api compliance format\nTODO: Figure out how to handle unpersisted ids", "itemtype": "method", "name": "jsonapi", @@ -710,7 +702,7 @@ }, { "file": "src/Model.js", - "line": 805, + "line": 798, "description": "Comparison by identity\nreturns `true` if this object has the same type and id as the\n\"other\" object, ignores differences in attrs and relationships", "itemtype": "method", "name": "isSame", @@ -757,7 +749,7 @@ }, { "file": "src/Store.js", - "line": 53, + "line": 54, "description": "Adds an instance or an array of instances to the store.\n```\nkpiHash = { name: \"A good thing to measure\" }\nkpi = store.add('kpis', kpiHash)\nkpi.name\n=> \"A good thing to measure\"\n```", "itemtype": "method", "name": "add", @@ -781,7 +773,7 @@ }, { "file": "src/Store.js", - "line": 74, + "line": 75, "description": "Given a set of properties and type, returns an object with only the properties\nthat are defined as attributes in the schema for that type.\n```\nproperties = { title: 'Do laundry', unrelatedProperty: 'Do nothing' }\npickAttributes(properties, 'todos')\n=> { title: 'Do laundry' }\n```", "itemtype": "method", "name": "pickAttributes", @@ -805,7 +797,7 @@ }, { "file": "src/Store.js", - "line": 92, + "line": 93, "description": "Given a set of properties and type, returns an object with only the properties\nthat are defined as relationships in the schema for that type.\n```\nproperties = { notes: [note1, note2], category: cat1, title: 'Fold Laundry' }\npickRelationships(properties, 'todos')\n=> {\n notes: {\n data: [{ id: '1', type: 'notes' }, { id: '2', type: 'notes' }]\n },\n category: {\n data: { id: '1', type: 'categories' }\n }\n }\n```", "itemtype": "method", "name": "pickRelationships", @@ -829,7 +821,7 @@ }, { "file": "src/Store.js", - "line": 132, + "line": 133, "description": "Builds an instance of a model that includes either an automatically or manually created temporary ID, but does not add it to the store.\nDoes not support relationships, since they require references to objects in the store.\n```\nkpiHash = { name: \"A good thing to measure\" }\nkpi = store.build('kpis', kpiHash)\nkpi.name\n=> \"A good thing to measure\"\n```", "itemtype": "method", "name": "build", @@ -853,7 +845,7 @@ }, { "file": "src/Store.js", - "line": 155, + "line": 156, "itemtype": "method", "name": "addModel", "params": [ @@ -876,7 +868,7 @@ }, { "file": "src/Store.js", - "line": 176, + "line": 177, "itemtype": "method", "name": "addModels", "params": [ @@ -899,7 +891,7 @@ }, { "file": "src/Store.js", - "line": 186, + "line": 187, "description": "Saves a collection of records via a bulk-supported JSONApi\nendpoint. All records need to be of the same type.", "itemtype": "method", "name": "bulkSave", @@ -924,7 +916,7 @@ }, { "file": "src/Store.js", - "line": 226, + "line": 227, "description": "Adds a record from the store. We can't simply remove the record\nby deleting the records property/key via delete due to a bug\nin mobx.", "itemtype": "method", "name": "remove", @@ -944,7 +936,7 @@ }, { "file": "src/Store.js", - "line": 240, + "line": 241, "description": "Gets a record from the store, will not fetch from the server if it doesn't exist in store.\nIf given queryParams, it will check the cache for the record.", "itemtype": "method", "name": "getOne", @@ -973,7 +965,7 @@ }, { "file": "src/Store.js", - "line": 263, + "line": 264, "description": "Fetches record by `id` from the server and returns a Promise.", "async": 1, "itemtype": "method", @@ -1003,7 +995,7 @@ }, { "file": "src/Store.js", - "line": 300, + "line": 301, "description": "Finds a record by `id`.\nIf available in the store, it returns that record. Otherwise, it fetches the record from the server.\n\n store.findOne('todos', 5)\n // fetch triggered\n => event1\n store.findOne('todos', 5)\n // no fetch triggered\n => event1", "itemtype": "method", "name": "findOne", @@ -1032,7 +1024,7 @@ }, { "file": "src/Store.js", - "line": 330, + "line": 331, "description": "Get all records with the given `type` and `ids` from the store. This will never fetch from the server.", "itemtype": "method", "name": "getMany", @@ -1061,7 +1053,7 @@ }, { "file": "src/Store.js", - "line": 346, + "line": 347, "description": "Fetch all records with the given `type` and `ids` from the server.", "itemtype": "method", "name": "fetchMany", @@ -1090,7 +1082,7 @@ }, { "file": "src/Store.js", - "line": 372, + "line": 373, "description": "Finds multiple records of the given `type` with the given `ids` and returns them wrapped in a Promise.\nIf all records are in the store, it returns those.\nIf some records are in the store, it returns those plus fetches all other records.\nOtherwise, it fetches all records from the server.\n\n store.findMany('todos', [1, 2, 3])\n // fetch triggered\n => [todo1, todo2, todo3]\n\n store.findMany('todos', [3, 2, 1])\n // no fetch triggered\n => [todo1, todo2, todo3]", "itemtype": "method", "name": "findMany", @@ -1119,7 +1111,7 @@ }, { "file": "src/Store.js", - "line": 422, + "line": 423, "description": "Builds fetch url based", "itemtype": "method", "name": "fetchUrl", @@ -1139,7 +1131,7 @@ }, { "file": "src/Store.js", - "line": 436, + "line": 437, "description": "Gets all records with the given `type` from the store. This will never fetch from the server.", "itemtype": "method", "name": "getAll", @@ -1163,7 +1155,7 @@ }, { "file": "src/Store.js", - "line": 453, + "line": 454, "description": "Finds all records with the given `type`. Always fetches from the server.", "async": 1, "itemtype": "method", @@ -1188,7 +1180,7 @@ }, { "file": "src/Store.js", - "line": 490, + "line": 491, "description": "Finds all records of the given `type`.\nIf all records are in the store, it returns those.\nOtherwise, it fetches all records from the server.\n\n store.findAll('todos')\n // fetch triggered\n => [todo1, todo2, todo3]\n\n store.findAll('todos')\n // no fetch triggered\n => [todo1, todo2, todo3]\n\nQuery params can be passed as part of the options hash.\nThe response will be cached, so the next time `findAll`\nis called with identical params and values, the store will\nfirst look for the local result.\n\n store.findAll('todos', {\n queryParams: {\n filter: {\n start_time: '2020-06-01T00:00:00.000Z',\n end_time: '2020-06-02T00:00:00.000Z'\n }\n }\n })\n\n\nNOTE: A broader RFC is in development to improve how we keep data in sync\nwith the server. We likely will want to getAll and getRecords\nto return null if nothing is found. However, this causes several regressions\nin portal we will need to address in a larger PR for mobx-async-store updates.", "itemtype": "method", "name": "findAll", @@ -1212,7 +1204,7 @@ }, { "file": "src/Store.js", - "line": 537, + "line": 538, "description": "Clears the store of a given type, or clears all if no type given\n\n store.reset('todos')\n // removes all todos from store\n store.reset()\n // clears store", "itemtype": "method", "name": "reset", @@ -1220,7 +1212,7 @@ }, { "file": "src/Store.js", - "line": 560, + "line": 561, "description": "Entry point for configuring the store", "itemtype": "method", "name": "init", @@ -1235,7 +1227,7 @@ }, { "file": "src/Store.js", - "line": 572, + "line": 573, "description": "Entry point for configuring the store", "itemtype": "method", "name": "initializeNetworkConfiguration", @@ -1250,7 +1242,7 @@ }, { "file": "src/Store.js", - "line": 584, + "line": 585, "description": "Entry point for configuring the store", "itemtype": "method", "name": "initializeNetworkConfiguration", @@ -1265,7 +1257,7 @@ }, { "file": "src/Store.js", - "line": 598, + "line": 599, "description": "Creates an obserable index with model types\nas the primary key\n\nObservable({ todos: {} })", "itemtype": "method", "name": "initializeObservableDataProperty", @@ -1273,7 +1265,7 @@ }, { "file": "src/Store.js", - "line": 619, + "line": 621, "description": "Wrapper around fetch applies user defined fetch options", "itemtype": "method", "name": "fetch", @@ -1293,7 +1285,7 @@ }, { "file": "src/Store.js", - "line": 647, + "line": 649, "description": "Gets type of collection from data observable", "itemtype": "method", "name": "getType", @@ -1312,7 +1304,7 @@ }, { "file": "src/Store.js", - "line": 658, + "line": 660, "description": "Gets individual record from store", "itemtype": "method", "name": "getRecord", @@ -1336,7 +1328,7 @@ }, { "file": "src/Store.js", - "line": 678, + "line": 680, "description": "Gets records for type of collection from observable\n\nNOTE: We only return records by unique id, this handles a scenario\nwhere the store keeps around a reference to a newly persisted record by its temp uuid.\nWe can't simply remove the temp uuid reference because other\nrelated models may be still using the temp uuid in their relationships\ndata object. However, when we are listing out records we want them\nto be unique by the persisted id (which is updated after a Model.save)", "itemtype": "method", "name": "getRecords", @@ -1355,7 +1347,7 @@ }, { "file": "src/Store.js", - "line": 699, + "line": 701, "description": "Get multiple records by id", "itemtype": "method", "name": "getRecordsById", @@ -1379,7 +1371,7 @@ }, { "file": "src/Store.js", - "line": 715, + "line": 717, "description": "Gets single from store based on cached query", "itemtype": "method", "name": "getCachedRecord", @@ -1407,7 +1399,7 @@ }, { "file": "src/Store.js", - "line": 730, + "line": 732, "description": "Gets records from store based on cached query", "itemtype": "method", "name": "getCachedRecords", @@ -1436,7 +1428,7 @@ }, { "file": "src/Store.js", - "line": 748, + "line": 750, "description": "Gets records from store based on cached query", "itemtype": "method", "name": "getCachedIds", @@ -1460,7 +1452,7 @@ }, { "file": "src/Store.js", - "line": 763, + "line": 765, "description": "Gets records from store based on cached query", "itemtype": "method", "name": "getCachedId", @@ -1484,7 +1476,7 @@ }, { "file": "src/Store.js", - "line": 775, + "line": 777, "description": "Helper to look up model class for type.", "itemtype": "method", "name": "getKlass", @@ -1503,7 +1495,7 @@ }, { "file": "src/Store.js", - "line": 786, + "line": 788, "description": "Creates or updates a model", "itemtype": "method", "name": "createOrUpdateModel", @@ -1518,7 +1510,7 @@ }, { "file": "src/Store.js", - "line": 826, + "line": 828, "description": "Create multiple models from an array of data", "itemtype": "method", "name": "createModelsFromData", @@ -1533,7 +1525,7 @@ }, { "file": "src/Store.js", - "line": 848, + "line": 850, "description": "Helper to create a new model", "itemtype": "method", "name": "createModel", @@ -1562,7 +1554,7 @@ }, { "file": "src/Store.js", - "line": 869, + "line": 871, "description": "Defines a resolution for an API call that will update a record or\nset of records with the data returned from the API", "itemtype": "method", "name": "updateRecords", diff --git a/docs/files/src_Model.js.html b/docs/files/src_Model.js.html index 3cc8d84e..586363ab 100644 --- a/docs/files/src_Model.js.html +++ b/docs/files/src_Model.js.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    @@ -89,7 +89,8 @@

    File: src/Model.js

    set, toJS, transaction, - observable + observable, + makeObservable } from 'mobx' import { diff, makeDate } from './utils' @@ -171,7 +172,14 @@

    File: src/Model.js

    * @method constructor */ constructor (initialAttributes = {}) { - this._makeObservable(initialAttributes) + makeObservable(this) + const { defaultAttributes } = this + + extendObservable(this, { + ...defaultAttributes, + ...initialAttributes + }) + this._takeSnapshot({ persisted: !this.isNew }) } @@ -548,21 +556,6 @@

    File: src/Model.js

    /* Private Methods */ - /** - * Magic method that makes changes to records - * observable - * - * @method _makeObservable - */ - _makeObservable (initialAttributes) { - const { defaultAttributes } = this - - extendObservable(this, { - ...defaultAttributes, - ...initialAttributes - }) - } - /** * The current state of defined attributes and relationships of the instance * Really just an alias for attributes diff --git a/docs/files/src_Store.js.html b/docs/files/src_Store.js.html index 1553a20f..d02c75e1 100644 --- a/docs/files/src_Store.js.html +++ b/docs/files/src_Store.js.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    @@ -84,7 +84,7 @@

    File: src/Store.js

     /* global fetch */
    -import { action, observable, set, toJS, transaction } from 'mobx'
    +import { action, makeObservable, observable, set, toJS, transaction } from 'mobx'
     import pick from 'lodash/pick'
     import uniqBy from 'lodash/uniqBy'
     import {
    @@ -131,6 +131,7 @@ 

    File: src/Store.js

    * @method constructor */ constructor (options) { + makeObservable(this) this.init(options) this.schema = schema } @@ -688,6 +689,7 @@

    File: src/Store.js

    * * @method initializeObservableDataProperty */ + @action initializeObservableDataProperty () { const { types } = this.constructor diff --git a/docs/files/src_decorators_attributes.js.html b/docs/files/src_decorators_attributes.js.html index e68c3e20..5fad5234 100644 --- a/docs/files/src_decorators_attributes.js.html +++ b/docs/files/src_decorators_attributes.js.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    diff --git a/docs/files/src_decorators_relationships.js.html b/docs/files/src_decorators_relationships.js.html index 83f8f42f..876b6823 100644 --- a/docs/files/src_decorators_relationships.js.html +++ b/docs/files/src_decorators_relationships.js.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    @@ -404,10 +404,6 @@

    File: src/decorators/relationships.js

    delete relationships[property] } - if (!Object.keys(record.relationships).length) { - delete record.relationships - } - // hack this will only work with singularized relationships. setRelatedRecord( relatedRecord, diff --git a/docs/files/src_schema.js.html b/docs/files/src_schema.js.html index 7dca5fce..7768085f 100644 --- a/docs/files/src_schema.js.html +++ b/docs/files/src_schema.js.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    diff --git a/docs/files/src_utils.js.html b/docs/files/src_utils.js.html index 95efc783..5b0359a9 100644 --- a/docs/files/src_utils.js.html +++ b/docs/files/src_utils.js.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    diff --git a/docs/index.html b/docs/index.html index 4ed65c2a..a0f053b9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -17,7 +17,7 @@

    - API Docs for: 3.10.3 + API Docs for: 4.0.0-rc.1
    diff --git a/package.json b/package.json index 9acd0d2f..6ed3daeb 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,15 @@ { "name": "@artemisag/mobx-async-store", - "version": "3.10.3", + "version": "4.0.0", "module": "dist/mobx-async-store.esm.js", "browser": "dist/mobx-async-store.cjs.js", "main": "dist/mobx-async-store.cjs.js", "dependencies": { "jsonapi-serializer": "^3.6.4", "lodash": "^4.17.21", - "mobx": "^5.15.7", + "mobx": "^6.3.2", "pluralize": "^8.0.0", "qs": "^6.9.4", - "react-native-uuid": "^2.0.1", "uuid": "^8.3.2" }, "devDependencies": { @@ -37,8 +36,7 @@ "jest-fetch-mock": "^3.0.3", "jsdom": "^16.0", "jsdom-global": "^3.0.0", - "mobx": "^5.15.7", - "mobx-react": "^5.4.3", + "mobx-react": "^7.2.0", "react": "^16.8.6", "react-dom": "^16.8.6", "rollup": "^2.50.5", diff --git a/spec/.babelrc b/spec/.babelrc index cbcdc9b7..c19af2c0 100644 --- a/spec/.babelrc +++ b/spec/.babelrc @@ -15,7 +15,7 @@ }, "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }], - ["@babel/plugin-proposal-class-properties", { "loose": true }], + ["@babel/plugin-proposal-class-properties", { "loose": false }], "@babel/plugin-transform-runtime" ] } diff --git a/spec/ExampleApp.js b/spec/ExampleApp.js index a93a3958..d8be6f7c 100644 --- a/spec/ExampleApp.js +++ b/spec/ExampleApp.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import { action, computed, + makeObservable, observable } from 'mobx' import { inject, observer } from 'mobx-react' @@ -9,27 +10,27 @@ import { inject, observer } from 'mobx-react' import PropTypes from 'prop-types' const todoCardPropTypes = { - store: PropTypes.object.isRequired, todo: PropTypes.object.isRequired } - -@inject('store') @observer +@observer class TodoCard extends Component { - @computed get todo () { - return this.props.todo + constructor () { + super() + makeObservable(this) } @action onChange = ({ target }) => { - this.todo.title = target.value + this.props.todo.title = target.value } render () { - const { onChange, todo } = this + const { onChange } = this + const { title } = this.props.todo return (
  • - +
  • @@ -37,7 +38,7 @@ class TodoCard extends Component { } } -TodoCard.wrappedComponent.propTypes = todoCardPropTypes +TodoCard.propTypes = todoCardPropTypes function TodoList ({ todos }) { return ( @@ -59,6 +60,11 @@ const exampleAppPropTypes = { @inject('store') @observer class ExampleApp extends Component { + constructor () { + super() + makeObservable(this) + } + @observable title = '' @action onChange = ({ target }) => { diff --git a/spec/Model.spec.js b/spec/Model.spec.js index d7fe7685..3405866a 100644 --- a/spec/Model.spec.js +++ b/spec/Model.spec.js @@ -7,7 +7,7 @@ import { validates } from '../src/main' /* global fetch */ -import { autorun, isObservable } from 'mobx' +import { autorun, isObservable, runInAction } from 'mobx' import { exampleRelatedToManyIncludedResponse, exampleRelatedToManyIncludedWithNoiseResponse, @@ -224,8 +224,13 @@ describe('Model', () => { } }) - todo.title = 'two' - todo.title = 'three' + runInAction(() => { + todo.title = 'two' + }) + + runInAction(() => { + todo.title = 'three' + }) }) it('attributes are overridable in constructor', () => { @@ -255,8 +260,13 @@ describe('Model', () => { } }) - todo.options.test = 'one' - todo.options.test = 'two' + runInAction(() => { + todo.options.test = 'one' + }) + + runInAction(() => { + todo.options.test = 'two' + }) }) it('attributes are observable', () => { diff --git a/spec/Store.spec.js b/spec/Store.spec.js index 644bee29..a3bcaac8 100644 --- a/spec/Store.spec.js +++ b/spec/Store.spec.js @@ -168,11 +168,12 @@ describe('Store', () => { }) it('initializes data observable', () => { + const map = new Map() expect(toJS(store.data)).toEqual({ - todos: { cache: {}, records: {} }, - notes: { cache: {}, records: {} }, - categories: { cache: {}, records: {} }, - tags: { cache: {}, records: {} } + todos: { cache: map, records: map }, + notes: { cache: map, records: map }, + categories: { cache: map, records: map }, + tags: { cache: map, records: map } }) }) @@ -850,7 +851,7 @@ describe('Store', () => { fetch.mockResponse(mockTodosResponse) await store.findAll('todos') const cache = toJS(store.data.todos.cache) - expect(cache['/example_api/todos']).toEqual(['1']) + expect(cache.get('/example_api/todos')).toEqual(['1']) }) it('fetched data snapshots are marked as persisted', async () => { @@ -1057,7 +1058,7 @@ describe('Store', () => { await store.fetchMany('todos', ['1']) const cache = toJS(store.data.todos.cache) - expect(cache['/example_api/todos?filter%5Bids%5D=1']).toEqual(['1']) + expect(cache.get('/example_api/todos?filter%5Bids%5D=1')).toEqual(['1']) }) }) @@ -1214,7 +1215,7 @@ describe('Store', () => { await store.findMany('todos', ['1']) const cache = toJS(store.data.todos.cache) - expect(cache['/example_api/todos?filter%5Bids%5D=1']).toEqual(['1']) + expect(cache.get('/example_api/todos?filter%5Bids%5D=1')).toEqual(['1']) }) }) diff --git a/spec/integration.spec.js b/spec/integration.spec.js index e4f323d6..361a87c3 100644 --- a/spec/integration.spec.js +++ b/spec/integration.spec.js @@ -65,7 +65,7 @@ describe('Example React App', () => { expect(wrapper.text()).toMatch('Buy Milk') }) - it('can edit an existing model', async () => { + it('can edit an existing model', () => { const todoStore = new AppStore() const todo = todoStore.add('todos', { title: 'Pay bills', options: { trackable_id: 1 } }) @@ -78,7 +78,7 @@ describe('Example React App', () => { expect(wrapper.text()).toMatch('Pay bills') - await wrapper + wrapper .find('input') .last() .simulate('change', { target: { value: 'Make payments' } }) diff --git a/src/.babelrc b/src/.babelrc index cbcdc9b7..c19af2c0 100644 --- a/src/.babelrc +++ b/src/.babelrc @@ -15,7 +15,7 @@ }, "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }], - ["@babel/plugin-proposal-class-properties", { "loose": true }], + ["@babel/plugin-proposal-class-properties", { "loose": false }], "@babel/plugin-transform-runtime" ] } diff --git a/src/Model.js b/src/Model.js index 1ad2b448..d43b8a51 100644 --- a/src/Model.js +++ b/src/Model.js @@ -4,7 +4,8 @@ import { set, toJS, transaction, - observable + observable, + makeObservable } from 'mobx' import { diff, makeDate } from './utils' @@ -86,7 +87,14 @@ class Model { * @method constructor */ constructor (initialAttributes = {}) { - this._makeObservable(initialAttributes) + makeObservable(this) + const { defaultAttributes } = this + + extendObservable(this, { + ...defaultAttributes, + ...initialAttributes + }) + this._takeSnapshot({ persisted: !this.isNew }) } @@ -463,21 +471,6 @@ class Model { /* Private Methods */ - /** - * Magic method that makes changes to records - * observable - * - * @method _makeObservable - */ - _makeObservable (initialAttributes) { - const { defaultAttributes } = this - - extendObservable(this, { - ...defaultAttributes, - ...initialAttributes - }) - } - /** * The current state of defined attributes and relationships of the instance * Really just an alias for attributes diff --git a/src/Store.js b/src/Store.js index 9293b489..70d305de 100644 --- a/src/Store.js +++ b/src/Store.js @@ -1,5 +1,5 @@ /* global fetch */ -import { action, observable, set, toJS, transaction } from 'mobx' +import { action, makeObservable, observable, set, toJS, transaction } from 'mobx' import pick from 'lodash/pick' import uniqBy from 'lodash/uniqBy' import { @@ -46,6 +46,7 @@ class Store { * @method constructor */ constructor (options) { + makeObservable(this) this.init(options) this.schema = schema } @@ -603,6 +604,7 @@ class Store { * * @method initializeObservableDataProperty */ + @action initializeObservableDataProperty () { const { types } = this.constructor diff --git a/src/decorators/relationships.js b/src/decorators/relationships.js index 22de8b32..962890f8 100644 --- a/src/decorators/relationships.js +++ b/src/decorators/relationships.js @@ -319,10 +319,6 @@ export class RelatedRecordsArray extends Array { delete relationships[property] } - if (!Object.keys(record.relationships).length) { - delete record.relationships - } - // hack this will only work with singularized relationships. setRelatedRecord( relatedRecord, diff --git a/yarn.lock b/yarn.lock index a0797348..8bc670a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2844,13 +2844,6 @@ hoek@0.9.x: resolved "https://registry.yarnpkg.com/hoek/-/hoek-0.9.1.tgz#3d322462badf07716ea7eb85baf88079cddce505" integrity sha1-PTIkYrrfB3Fup+uFuviAec3c5QU= -hoist-non-react-statics@^3.0.0: - version "3.3.1" - resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#101685d3aff3b23ea213163f6e8e12f4f111e19f" - integrity sha512-wbg3bpgA/ZqWrZuMOeJi8+SKMhr7X9TesL/rXMjTzh0p0JUBo3II8DHboYbuIXWRlttrUFxwcu/5kygrCw8fJw== - dependencies: - react-is "^16.7.0" - hosted-git-info@^2.1.4: version "2.8.9" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" @@ -3969,18 +3962,22 @@ mkdirp@0.5.1: dependencies: minimist "0.0.8" -mobx-react@^5.4.3: - version "5.4.4" - resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-5.4.4.tgz#b3de9c6eabcd0ed8a40036888cb0221ab9568b80" - integrity sha512-2mTzpyEjVB/RGk2i6KbcmP4HWcAUFox5ZRCrGvSyz49w20I4C4qql63grPpYrS9E9GKwgydBHQlA4y665LuRCQ== +mobx-react-lite@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-3.2.0.tgz#331d7365a6b053378dfe9c087315b4e41c5df69f" + integrity sha512-q5+UHIqYCOpBoFm/PElDuOhbcatvTllgRp3M1s+Hp5j0Z6XNgDbgqxawJ0ZAUEyKM8X1zs70PCuhAIzX1f4Q/g== + +mobx-react@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-7.2.0.tgz#241e925e963bb83a31d269f65f9f379e37ecbaeb" + integrity sha512-KHUjZ3HBmZlNnPd1M82jcdVsQRDlfym38zJhZEs33VxyVQTvL77hODCArq6+C1P1k/6erEeo2R7rpE7ZeOL7dg== dependencies: - hoist-non-react-statics "^3.0.0" - react-lifecycles-compat "^3.0.2" + mobx-react-lite "^3.2.0" -mobx@^5.15.7: - version "5.15.7" - resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.15.7.tgz#b9a5f2b6251f5d96980d13c78e9b5d8d4ce22665" - integrity sha512-wyM3FghTkhmC+hQjyPGGFdpehrcX1KOXsDuERhfK2YbJemkUhEB+6wzEN639T21onxlfYBmriA1PFnvxTUhcKw== +mobx@^6.3.2: + version "6.3.2" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.3.2.tgz#125590961f702a572c139ab69392bea416d2e51b" + integrity sha512-xGPM9dIE1qkK9Nrhevp0gzpsmELKU4MFUJRORW/jqxVFIHHWIoQrjDjL8vkwoJYY3C2CeVJqgvl38hgKTalTWg== moo@^0.4.3: version "0.4.3" @@ -4494,7 +4491,7 @@ react-dom@^16.8.6: prop-types "^15.6.2" scheduler "^0.19.1" -react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6: +react-is@^16.13.1, react-is@^16.8.1, react-is@^16.8.6: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== @@ -4504,16 +4501,6 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-lifecycles-compat@^3.0.2: - version "3.0.4" - resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" - integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== - -react-native-uuid@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/react-native-uuid/-/react-native-uuid-2.0.1.tgz#ed4e2dfb1683eddb66967eb5dca140dfe1abddb9" - integrity sha512-cptnoIbL53GTCrWlb/+jrDC6tvb7ypIyzbXNJcpR3Vab0mkeaaVd5qnB3f0whXYzS+SMoSQLcUUB0gEWqkPC0g== - react-test-renderer@^16.0.0-0: version "16.14.0" resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.14.0.tgz#e98360087348e260c56d4fe2315e970480c228ae"