Comparing version
@@ -31,5 +31,5 @@ 'use strict'; | ||
/** | ||
* Custom Error | ||
* @param { Object } settings | ||
*/ | ||
* Custom Error | ||
* @param { Object } settings | ||
*/ | ||
var StoreError = function StoreError(settings) { | ||
@@ -44,5 +44,5 @@ this.name = 'RxStoreError'; | ||
/** | ||
* Determines if the wrapped component is a React Component | ||
* @param {Class or Function} target | ||
*/ | ||
* Determines if the wrapped component is a React Component | ||
* @param {Class or Function} target | ||
*/ | ||
var isReactComponent = function isReactComponent(target, func) { | ||
@@ -72,4 +72,4 @@ if (!target || !(target.prototype instanceof _react.Component)) { | ||
/** | ||
* Remove all listeners | ||
*/ | ||
* Remove all listeners | ||
*/ | ||
var removeAllListeners = exports.removeAllListeners = function removeAllListeners() { | ||
@@ -80,5 +80,5 @@ return stateSubject.dispose(); | ||
/** | ||
* React decorator, decorates a React component | ||
* @return {ReactComponent} | ||
*/ | ||
* React decorator, decorates a React component | ||
* @return {ReactComponent} | ||
*/ | ||
var connect = exports.connect = function connect() { | ||
@@ -100,5 +100,5 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
/** | ||
* It is called when the Subjects stops pushing values | ||
*/ | ||
target.prototype.onComplete = function () { | ||
* It is called when the Subjects stops pushing values | ||
*/ | ||
target.prototype.onComplete = function onComp() { | ||
onComplete.call(this); | ||
@@ -108,10 +108,10 @@ }; | ||
/** | ||
* It is called when an error happens on the store | ||
* @param {Error object} err | ||
*/ | ||
target.prototype.onError = function (err) { | ||
* It is called when an error happens on the store | ||
* @param {Error object} err | ||
*/ | ||
target.prototype.onError = function onErr(err) { | ||
/* isStopped is passed by rx and means that the stream has | ||
stopped due to an error, in that case err.message is not so | ||
meaningfull and its better to pass the stack as message, | ||
that can could change in the future */ | ||
stopped due to an error, in that case err.message is not so | ||
meaningfull and its better to pass the stack as message, | ||
that can could change in the future */ | ||
var message = this.isStopped ? err.stack : err.message; | ||
@@ -128,6 +128,6 @@ | ||
/** | ||
* Set the listener on componentWillMount | ||
* Listener will setState | ||
*/ | ||
target.prototype.componentWillMount = function () { | ||
* Set the listener on componentWillMount | ||
* Listener will setState | ||
*/ | ||
target.prototype.componentWillMount = function componentWillMount() { | ||
var _this = this; | ||
@@ -145,5 +145,5 @@ | ||
/** | ||
* Remove subscriber on componentWillUnmount | ||
*/ | ||
target.prototype.componentWillUnmount = function () { | ||
* Remove subscriber on componentWillUnmount | ||
*/ | ||
target.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.unsubscribe(); | ||
@@ -154,5 +154,5 @@ willUnmount.call(this); | ||
/** | ||
* Provide an unsubscribe function to the underline component | ||
*/ | ||
target.prototype.unsubscribe = function () { | ||
* Provide an unsubscribe function to the underline component | ||
*/ | ||
target.prototype.unsubscribe = function unsubscribe() { | ||
try { | ||
@@ -159,0 +159,0 @@ this.__subscription.dispose(); |
{ | ||
"name": "dugong", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Minimal State Container for React Apps using RxJS", | ||
"scripts": { | ||
"test": "npm run compiletests && mocha --compilers js:babel-register --require babel-polyfill", | ||
"compiletests": "babel --presets es2015,stage-0,react --plugins transform-decorators-legacy -d test/ testsrc/", | ||
"test": "jest", | ||
"compile": "babel --presets es2015,stage-0,react -d lib/ src/", | ||
"prepublish": "npm run compile", | ||
"lint": "eslint ./src --fix", | ||
"watch": "npm-scripts-watcher" | ||
@@ -39,4 +39,4 @@ }, | ||
"peerDependencies": { | ||
"react": "^15.4.2", | ||
"lodash": "^4.17.4" | ||
"lodash": "^4.17.4", | ||
"react": "^15.4.2" | ||
}, | ||
@@ -46,3 +46,3 @@ "devDependencies": { | ||
"babel-core": "^6.22.1", | ||
"babel-eslint": "^7.1.1", | ||
"babel-eslint": "^8.2.6", | ||
"babel-plugin-syntax-object-rest-spread": "^6.13.0", | ||
@@ -54,25 +54,23 @@ "babel-plugin-transform-decorators": "^6.22.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-preset-react": "^6.22.0", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-0": "^6.22.0", | ||
"babel-register": "^6.22.0", | ||
"chai": "^3.5.0", | ||
"enzyme": "^2.7.1", | ||
"eslint": "^3.15.0", | ||
"eslint-config-airbnb": "^14.1.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^4.0.0", | ||
"eslint-plugin-react": "^6.9.0", | ||
"enzyme": "3.4.2", | ||
"enzyme-adapter-react-16": "^1.2.0", | ||
"eslint": "^5.3.0", | ||
"eslint-config-airbnb-base": "^13.0.0", | ||
"eslint-config-avraam": "^1.0.0", | ||
"eslint-plugin-import": "^2.13.0", | ||
"eslint-plugin-react": "^7.11.1", | ||
"jest": "^23.5.0", | ||
"mocha": "^3.2.0", | ||
"promise": "^7.1.1", | ||
"react": "^15.4.2", | ||
"react-addons-test-utils": "^15.4.2", | ||
"react-dom": "^15.4.2", | ||
"rx": "^4.1.0", | ||
"sinon": "^1.17.7", | ||
"sinon-chai": "^2.8.0" | ||
"react-addons-test-utils": "^15.6.2", | ||
"react-dom": "^16.0.0" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.4", | ||
"react": "^16.0.0", | ||
"rx": "^4.1.0" | ||
} | ||
} |
@@ -1,59 +0,27 @@ | ||
'use strict'; | ||
import React, { Component } from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { connect, createStore, updateStore } from '../lib/index.js'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _dec, _class; | ||
createStore({ something: 10 }); | ||
var _index = require('../lib/index.js'); | ||
var _chai = require('chai'); | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _enzyme = require('enzyme'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
(0, _index.createStore)({ something: 10 }); | ||
var Test = (_dec = (0, _index.connect)('something'), _dec(_class = function (_Component) { | ||
_inherits(Test, _Component); | ||
function Test() { | ||
_classCallCheck(this, Test); | ||
return _possibleConstructorReturn(this, (Test.__proto__ || Object.getPrototypeOf(Test)).apply(this, arguments)); | ||
@connect('something') | ||
class Test extends Component { | ||
render() { | ||
return <div></div>; | ||
} | ||
} | ||
_createClass(Test, [{ | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement('div', null); | ||
} | ||
}]); | ||
return Test; | ||
}(_react.Component)) || _class); | ||
describe('<Test /> @connect', function () { | ||
it('should get the right initial state with @connect', function () { | ||
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Test, null)); | ||
(0, _chai.expect)(wrapper.state('something')).to.equal(10); | ||
describe('<Test /> @connect', () => { | ||
it('should get the right initial state with @connect', () => { | ||
const wrapper = shallow(<Test />); | ||
expect(wrapper.state('something')).toEqual(10); | ||
}); | ||
it('should update components state when the store is updated', function () { | ||
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Test, null)); | ||
(0, _index.updateStore)({ something: 100 }); | ||
(0, _chai.expect)(wrapper.state('something')).to.equal(100); | ||
it('should update components state when the store is updated', () => { | ||
const wrapper = shallow(<Test />); | ||
updateStore({ something: 100 }); | ||
expect(wrapper.state('something')).toEqual(100); | ||
}); | ||
}); | ||
}); |
@@ -1,38 +0,29 @@ | ||
'use strict'; | ||
import { BehaviorSubject } from 'rx'; | ||
var _index = require('../lib/index.js'); | ||
import { | ||
createStore, updateStore, getStore, getLastState | ||
} from '../lib/index.js'; | ||
var _chai = require('chai'); | ||
describe('Dugong', () => { | ||
beforeEach(() => { | ||
createStore({ something: 5 }); | ||
}); | ||
var _rx = require('rx'); | ||
it('should createStore with initial state', () => { | ||
expect(getStore().value.something).toEqual(5); | ||
}); | ||
var _react = require('react'); | ||
it('should return a BehaviorSubject on getStore()', () => { | ||
expect(getStore() instanceof BehaviorSubject).toEqual(true); | ||
}); | ||
var _react2 = _interopRequireDefault(_react); | ||
it('should update the store on updateStore()', () => { | ||
updateStore({ something: 10 }); | ||
expect(getStore().value.something).toEqual(10); | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('Chimera', function () { | ||
beforeEach(function () { | ||
(0, _index.createStore)({ something: 5 }); | ||
}); | ||
it('should createStore with initial state', function () { | ||
(0, _chai.expect)((0, _index.getStore)().value.something).to.equal(5); | ||
}); | ||
it('should return a BehaviorSubject on getStore()', function () { | ||
(0, _chai.expect)((0, _index.getStore)() instanceof _rx.BehaviorSubject).to.equal(true); | ||
}); | ||
it('should update the store on updateStore()', function () { | ||
(0, _index.updateStore)({ something: 10 }); | ||
(0, _chai.expect)((0, _index.getStore)().value.something).to.equal(10); | ||
}); | ||
it('should return the last state on getLastState()', function () { | ||
(0, _index.updateStore)({ something: 100 }); | ||
(0, _chai.expect)((0, _index.getLastState)().something).to.equal(100); | ||
}); | ||
}); | ||
it('should return the last state on getLastState()', () => { | ||
updateStore({ something: 100 }); | ||
expect(getLastState().something).toEqual(100); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
192959
49.78%24
-11.11%5
25%212
-13.47%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed