Skip to content

Commit

Permalink
Remove moment (#54)
Browse files Browse the repository at this point in the history
* remove dependency on moment.js

* remove unused code

I guess it wasn't clear if this was used because attribute was exported
from Model.js, but the same code is defined in decorators/attributes.js
and it appears to always be imported from that module everywhere that
it's used

* v1.0.26
  • Loading branch information
jordanstephens authored Jun 22, 2020
1 parent 91b5dc4 commit 872c563
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 573 deletions.
21 changes: 16 additions & 5 deletions dist/mobx-async-store.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var _applyDecoratedDescriptor = _interopDefault(require('@babel/runtime/helpers/
require('@babel/runtime/helpers/initializerWarningHelper');
var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof'));
var mobx = require('mobx');
var moment = _interopDefault(require('moment'));
var uuidv1 = _interopDefault(require('uuid/v1'));
var jqueryParam = _interopDefault(require('jquery-param'));
var pluralize = _interopDefault(require('pluralize'));
Expand Down Expand Up @@ -161,6 +160,18 @@ function uniqueByReducer(key) {
function uniqueBy(array, key) {
return array.reduce(uniqueByReducer(key), []);
}
/**
* convert a value into a date, pass Date or Moment instances thru
* untouched
* @method makeDate
* @param {*} value
* @return {Date|Moment}
*/

function makeDate(value) {
if (value instanceof Date || value._isAMomentObject) return value;
return new Date(Date.parse(value));
}
/**
* recursively walk an object and call the `iteratee` function for
* each property. returns an array of results of calls to the iteratee.
Expand Down Expand Up @@ -425,7 +436,6 @@ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) {
* @return {Array} an array of booleans representing results of validations
*/


function validateProperties(model, propertyNames, propertyDefinitions) {
return propertyNames.map(function (property) {
var validator = propertyDefinitions[property].validator;
Expand Down Expand Up @@ -481,6 +491,7 @@ function stringifyIds(object) {
@class Model
*/


var Model = (_class = (_temp =
/*#__PURE__*/
function () {
Expand Down Expand Up @@ -998,7 +1009,7 @@ function () {
if (DataType.name === 'Array' || DataType.name === 'Object') {
attr = mobx.toJS(value);
} else if (DataType.name === 'Date') {
attr = moment(value).toISOString();
attr = makeDate(value).toISOString();
} else {
attr = DataType(value);
}
Expand Down Expand Up @@ -2166,7 +2177,7 @@ function defaultValueForDescriptor(descriptor, DataType) {
var value = descriptor.initializer();

if (DataType.name === 'Date') {
return moment(value).toDate();
return makeDate(value);
} else {
return DataType(value);
}
Expand All @@ -2182,7 +2193,7 @@ function defaultValueForDescriptor(descriptor, DataType) {
* Attributes can be defined with a default.
* ```
* class Todo extends Model {
* @attribute(Date) start_time = moment()
* @attribute(Date) start_time = new Date()
* }
* ```
* @method attribute
Expand Down
21 changes: 16 additions & 5 deletions dist/mobx-async-store.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import _applyDecoratedDescriptor from '@babel/runtime/helpers/applyDecoratedDesc
import '@babel/runtime/helpers/initializerWarningHelper';
import _typeof from '@babel/runtime/helpers/typeof';
import { transaction, set, observable, computed, extendObservable, reaction, toJS, action } from 'mobx';
import moment from 'moment';
import uuidv1 from 'uuid/v1';
import jqueryParam from 'jquery-param';
import pluralize from 'pluralize';
Expand Down Expand Up @@ -155,6 +154,18 @@ function uniqueByReducer(key) {
function uniqueBy(array, key) {
return array.reduce(uniqueByReducer(key), []);
}
/**
* convert a value into a date, pass Date or Moment instances thru
* untouched
* @method makeDate
* @param {*} value
* @return {Date|Moment}
*/

function makeDate(value) {
if (value instanceof Date || value._isAMomentObject) return value;
return new Date(Date.parse(value));
}
/**
* recursively walk an object and call the `iteratee` function for
* each property. returns an array of results of calls to the iteratee.
Expand Down Expand Up @@ -419,7 +430,6 @@ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) {
* @return {Array} an array of booleans representing results of validations
*/


function validateProperties(model, propertyNames, propertyDefinitions) {
return propertyNames.map(function (property) {
var validator = propertyDefinitions[property].validator;
Expand Down Expand Up @@ -475,6 +485,7 @@ function stringifyIds(object) {
@class Model
*/


var Model = (_class = (_temp =
/*#__PURE__*/
function () {
Expand Down Expand Up @@ -992,7 +1003,7 @@ function () {
if (DataType.name === 'Array' || DataType.name === 'Object') {
attr = toJS(value);
} else if (DataType.name === 'Date') {
attr = moment(value).toISOString();
attr = makeDate(value).toISOString();
} else {
attr = DataType(value);
}
Expand Down Expand Up @@ -2160,7 +2171,7 @@ function defaultValueForDescriptor(descriptor, DataType) {
var value = descriptor.initializer();

if (DataType.name === 'Date') {
return moment(value).toDate();
return makeDate(value);
} else {
return DataType(value);
}
Expand All @@ -2176,7 +2187,7 @@ function defaultValueForDescriptor(descriptor, DataType) {
* Attributes can be defined with a default.
* ```
* class Todo extends Model {
* @attribute(Date) start_time = moment()
* @attribute(Date) start_time = new Date()
* }
* ```
* @method attribute
Expand Down
Loading

0 comments on commit 872c563

Please sign in to comment.