Skip to content

Commit

Permalink
Update sanctuary-type-identifiers to version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed May 5, 2020
1 parent 83b0894 commit d3c2a25
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
],
"dependencies": {
"sanctuary-show": "^2.0.0",
"sanctuary-type-identifiers": "^2.0.0"
"sanctuary-type-identifiers": "^3.0.0"
},
"devDependencies": {
"c8": "^7.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/future.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export function isFuture(x){
return x instanceof Future || type(x) === $$type;
}

// Compliance to sanctuary-type-identifiers version 1 and 2.
// In order to prevent sanctuary-type-identifiers version 3 from identifying
// Future as a type of $$type, we ensure that Future.constructor.prototype is
// equal to Future.
Future['@@type'] = $$type;
Future.constructor = {prototype: Future};

Future[FL.of] = resolve;
Future[FL.chainRec] = chainRec;

Expand Down
5 changes: 5 additions & 0 deletions src/par.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export function Par (sequential){
var $$type = namespace + '/ConcurrentFuture@' + version;
var zeroInstance = new ConcurrentFuture(never);

// Compliance to sanctuary-type-identifiers version 1 and 2.
// In order to prevent sanctuary-type-identifiers version 3 from identifying
// Par as a type of $$type, we ensure that Par.constructor.prototype is
// equal to Par.
Par['@@type'] = $$type;
Par.constructor = {prototype: Par};

Par[FL.of] = function Par$of(x){
return new ConcurrentFuture(resolve(x));
Expand Down
2 changes: 2 additions & 0 deletions test/arbitraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const {
jsv.bool,
jsv.falsy,
jsv.constant(new Error('Kapot')),
jsv.constant(Future),
jsv.constant(Par),
tie('anyFunction')
),
any: jsv.oneof(
Expand Down
5 changes: 3 additions & 2 deletions test/assertions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import show from 'sanctuary-show';
import type from 'sanctuary-type-identifiers';
import {Future, isFuture} from '../index.js';
import {isFuture} from '../index.js';
import {$$type} from '../src/internal/const.js';
import {strictEqual, deepStrictEqual} from 'assert';

const states = ['pending', 'crashed', 'rejected', 'resolved'];
Expand All @@ -13,7 +14,7 @@ export const equality = a => b => {

export const future = x => {
equality(isFuture(x))(true);
equality(type(x))(Future['@@type']);
equality(type(x))($$type);
return true;
};

Expand Down
2 changes: 1 addition & 1 deletion test/unit/0.error.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('invalidArity constructs a TypeError', function (){
});

var mockType = function (identifier){
return {'constructor': {'@@type': identifier}, '@@show': function (){
return {'@@type': identifier, '@@show': function (){
return 'mockType("' + identifier + '")';
}};
};
Expand Down

0 comments on commit d3c2a25

Please sign in to comment.