Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

statetransition-mixin

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statetransition-mixin - npm Package Compare versions

Comparing version 1.4.2 to 1.4.3

2

package.json

@@ -38,3 +38,3 @@ {

"homepage": "https://github.com/arlac77/statetransition-mixin#readme",
"version": "1.4.2"
"version": "1.4.3"
}

@@ -104,3 +104,8 @@ /* jslint node: true, esnext: true */

Object.assign(object, BaseMethods);
Object.keys(BaseMethods).forEach(name => {
if (object[name] === undefined) {
object[name] = BaseMethods[name];
}
});
Object.defineProperties(object, properties);

@@ -164,12 +169,8 @@ };

return promise.then(fullfilled => {
clearTimeout(th);
fullfill(fullfilled);
}, rejected => {
clearTimeout(th);
reject(rejected);
})
.catch(r => {
clearTimeout(th);
reject(r);
});
clearTimeout(th);
fullfill(fullfilled);
}, rejected => {
clearTimeout(th);
reject(rejected);
});
});

@@ -229,8 +230,12 @@ }

if (action.initial[this.state]) {
// some transition is ongoing
if (this._transition) {
const t = this._transition;
// we terminate it silently ?
// then do what we originally wanted
return this.stateTransitionRejection(new Error(
`Terminate ${t.name} to prepare ${actionName}`), this.state).
`Terminate ${t.name} to prepare ${actionName}`), t.initial).
then(f => {}, r => {
//console.log(`${actionName} after rejecting ${t.name}`);
return this[actionName]();

@@ -246,6 +251,12 @@ });

resolved => {
if (!this._transition) {
// here we end if we canceled a transtion
// need some better ideas to communicate
return this;
/*
return this.stateTransitionRejection(new Error(
`Should never happen: ${this.state} and no transition coming from ${actionName}`
), 'failed');
*/
}

@@ -252,0 +263,0 @@

@@ -29,3 +29,3 @@ /* global describe, it, xit */

during: "stopping",
timeout: 100
timeout: 0
}

@@ -43,10 +43,13 @@ },

class StatefullClass extends stm.StateTransitionMixin(BaseClass, actions, 'stopped') {
constructor(startTime, shouldReject) {
constructor(startTime, shouldReject, shouldThrow) {
super();
this.startTime = startTime;
this.shouldReject = shouldReject;
this.shouldThrow = shouldThrow;
}
_start() {
if (this.shouldReject) return Promise.reject(new Error("always reject"));
if (this.startTime === 0) {
if (this.shouldReject) return Promise.reject(new Error("always reject"));
if (this.shouldThrow) throw new Error("always throw");
}
return new Promise((f, r) => {

@@ -56,3 +59,5 @@ setTimeout(() => {

r(Promise.reject(new Error("always reject")));
} else {
}
if (this.shouldThrow) throw new Error("always throw");
else {
f(this);

@@ -76,3 +81,3 @@ }

describe('plain object', function () {
checks((startTime, shouldReject) => {
checks((startTime, shouldReject, shouldThrow) => {
const o = {

@@ -83,3 +88,6 @@ toString() {

_start() {
if (shouldReject) return Promise.reject(new Error("always reject"));
if (startTime === 0) {
if (shouldReject) return Promise.reject(new Error("always reject"));
if (shouldThrow) throw new Error("always throw");
}

@@ -90,3 +98,5 @@ return new Promise((f, r) => {

r(Promise.reject(new Error("always reject")));
} else {
}
if (this.shouldThrow) throw new Error("always throw");
else {
f(this);

@@ -181,3 +191,3 @@ }

it('illegal transition', function (done) {
const o = factory(0, false);
const o = factory(0, false, false);
try {

@@ -198,3 +208,3 @@ o.swim().then(() => {

it('handle timeout while starting', function (done) {
const o = factory(1000, false);
const o = factory(1000, false, false);
o.start().then(() => {}).catch(e => {

@@ -206,25 +216,32 @@ assert.equal(o.state, 'failed');

it('handle failure while starting without timeout guard', function (done) {
const o = factory(0, true);
chechFailure('failure (reject)', true, false);
chechFailure('failure (throw)', false, true);
o.start().then((f, r) => {
console.log(`${f} ${r}`);
}).catch(e => {
assert.equal(o.state, 'failed');
done();
function chechFailure(name, shouldReject, shoudThrow) {
it(`handle ${name} while starting without timeout guard`, function (done) {
const o = factory(0, true, false);
o.start().then((f, r) => {
console.log(`${f} ${r}`);
}).catch(e => {
console.log(`catch ${name} ${e}`);
assert.equal(o.state, 'failed');
done();
});
});
});
it('handle failure while starting with timeout guard', function (done) {
const o = factory(10, true);
it(`handle ${name} while starting with timeout guard`, function (done) {
const o = factory(10, true, false);
o.start().then((f, r) => {
console.log(`${f} ${r}`);
}).catch(e => {
assert.equal(o.state, 'failed');
done();
o.start().then((f, r) => {
console.log(`${f} ${r}`);
}).catch(e => {
console.log(`catch ${name} ${e}`);
assert.equal(o.state, 'failed');
done();
});
});
});
}
});
});
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc