Skip to content

Commit

Permalink
Merge pull request #196 from monet/fix-exports-even-more
Browse files Browse the repository at this point in the history
Fix exports
  • Loading branch information
ulfryk authored Nov 18, 2018
2 parents 84b6aca + dfd5de9 commit 3660986
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 94 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.9.0

### rc.3 (18 Nov 2018)

- [fix] broken exports ( #196 )

### rc.2 (18 Nov 2018)

- [fix] broken UMD for node imports ( #193 )
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"name": "monet",
"description": "Monadic types library for JavaScript",
"version": "0.9.0-rc.2",
"version": "0.9.0-rc.3",
"homepage": "https://monet.github.io/monet.js/",
"repository": {
"type": "git",
Expand Down
11 changes: 7 additions & 4 deletions prepublish-test/browser-global.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
describe('global Monet object', function () {
describe('Browser: global Monet object', function () {
it('should be available', function () {
expect(Monet).toBeDefined()
expect(Maybe).toBeDefined()
expect(Either).toBeDefined()
expect(Validation.success).toBe(Success)
expect(Monet.Maybe).toBeDefined()
expect(Monet.Either).toBeDefined()
expect(Monet.Validation.success).toBe(Monet.Success)

expect(() => Maybe).toThrow()
expect(() => Either).toThrow()
})
})
14 changes: 8 additions & 6 deletions prepublish-test/node-global.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
global.useMonetGlobalObject = true // run browser style tests
require('../dist/monet.js')
global.Monet = require('../dist/monet.js')

describe('global Monet object', function () {
describe('Node: global Monet object', function () {
it('should be available', function () {
expect(Monet).toBeDefined()
expect(Maybe).toBeDefined()
expect(Either).toBeDefined()
expect(Validation.success).toBe(Success)
expect(Monet.Maybe).toBeDefined()
expect(Monet.Either).toBeDefined()
expect(Monet.Validation.success).toBe(Monet.Success)

expect(() => Maybe).toThrow()
expect(() => Either).toThrow()
})
})
2 changes: 1 addition & 1 deletion prepublish-test/node-regular.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const monet = require('../dist/monet.js')

describe('monet.js exports object', function () {
describe('Node: monet.js exports object', function () {
it('should be available', function () {
expect(monet).toBeDefined()
expect(monet.Maybe).toBeDefined()
Expand Down
2 changes: 1 addition & 1 deletion src/monet-pimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if (typeof define === 'function' && define.amd) {
define(['monet'], factory)
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('monet'), typeof global === 'object' ? global : root)
module.exports = factory(require('monet'), root)
} else {
factory(root.Monet, root)
}
Expand Down
71 changes: 23 additions & 48 deletions src/monet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@
if (typeof define === 'function' && define.amd) {
define(factory)
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(typeof global === 'object' ? global : root)
module.exports = factory(root)
} else {
root.useMonetGlobalObject =
typeof root.useMonetGlobalObject === 'boolean' ?
root.useMonetGlobalObject :
true
root.Monet = factory(root)
}
}(typeof self !== 'undefined' ? self : this, function (rootGlobalObject) {
}(typeof self !== 'undefined' ? self : this, function () {
'use strict'

var root = {}

function assignImp(target, source) {
for (var key in source) { // we need only one level of composition
// eslint-disable-next-line no-undefined
Expand Down Expand Up @@ -242,7 +236,7 @@
}
}

root.List = List
Monet.List = List

var listForEach = function (effectFn, l) {
if (!l.isNil) {
Expand Down Expand Up @@ -362,9 +356,6 @@
}, [], this)
},
toSet: function () {
if (!rootGlobalObject.Set) {
throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.')
}
return new Set(this)
},
foldLeft: function (initialValue) {
Expand Down Expand Up @@ -479,7 +470,7 @@
// backwards compatibility, deprecated
List.prototype.each = List.prototype.forEach

Nil = root.Nil = new List.fn.init()
Nil = Monet.Nil = new List.fn.init()

/*
* Non-Empty List monad
Expand All @@ -499,7 +490,7 @@
return new NEL.fn.init(head, tail)
}

root.NEL = root.NonEmptyList = NEL
Monet.NEL = Monet.NonEmptyList = NEL

NEL.of = function (a) {
return NEL(a, Nil)
Expand Down Expand Up @@ -637,7 +628,7 @@

/* Maybe Monad */

var Maybe = root.Maybe = {}
var Maybe = Monet.Maybe = {}

Maybe.fromFalsy = function (val) {
return !val ? Maybe.None() : Maybe.Some(val)
Expand All @@ -656,11 +647,11 @@
return Some(a)
}

var Some = Maybe.Just = Maybe.Some = Maybe.some = root.Some = root.Just = function (val) {
var Some = Maybe.Just = Maybe.Some = Maybe.some = Monet.Some = Monet.Just = function (val) {
return new Maybe.fn.init(true, val)
}

var None = Maybe.Nothing = Maybe.None = Maybe.none = root.None = root.Nothing = function () {
var None = Maybe.Nothing = Maybe.None = Maybe.none = Monet.None = Monet.Nothing = function () {
return new Maybe.fn.init(false, null)
}

Expand Down Expand Up @@ -730,9 +721,6 @@
})
},
toSet: function () {
if (!rootGlobalObject.Set) {
throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.')
}
return new Set(this)
},
toList: function () {
Expand Down Expand Up @@ -803,13 +791,13 @@
Maybe.isInstance = isInstance(TYPES_NAMES.Maybe)
Maybe.isOfType = isOfType(TYPES_NAMES.Maybe)

var Validation = root.Validation = {}
var Validation = Monet.Validation = {}

var Success = Validation.Success = Validation.success = root.Success = function (val) {
var Success = Validation.Success = Validation.success = Monet.Success = function (val) {
return new Validation.fn.init(val, true)
}

var Fail = Validation.Fail = Validation.fail = root.Fail = function (error) {
var Fail = Validation.Fail = Validation.fail = Monet.Fail = function (error) {
return new Validation.fn.init(error, false)
}

Expand Down Expand Up @@ -923,7 +911,7 @@
Validation.isInstance = isInstance(TYPES_NAMES.Validation)
Validation.isOfType = isOfType(TYPES_NAMES.Validation)

var Semigroup = root.Semigroup = {
var Semigroup = Monet.Semigroup = {
append: function (a, b) {
if (isFunction(a.concat)) {
return a.concat(b)
Expand All @@ -934,7 +922,7 @@
}
}

var MonadT = root.monadTransformer = root.MonadT = root.monadT = function (monad) {
var MonadT = Monet.monadTransformer = Monet.MonadT = Monet.monadT = function (monad) {
return new MonadT.fn.init(monad)
}

Expand Down Expand Up @@ -971,7 +959,7 @@

MonadT.fn.init.prototype = MonadT.fn

var IO = root.IO = root.io = function (effectFn) {
var IO = Monet.IO = Monet.io = function (effectFn) {
return new IO.fn.init(effectFn)
}

Expand Down Expand Up @@ -1023,16 +1011,16 @@

/* Either Monad */

var Either = root.Either = {}
var Either = Monet.Either = {}

Either.of = function (a) {
return Right(a)
}

var Right = Either.Right = Either.right = root.Right = function (val) {
var Right = Either.Right = Either.right = Monet.Right = function (val) {
return new Either.fn.init(val, true)
}
var Left = Either.Left = Either.left = root.Left = function (val) {
var Left = Either.Left = Either.left = Monet.Left = function (val) {
return new Either.fn.init(val, false)
}

Expand Down Expand Up @@ -1133,7 +1121,7 @@
Either.isInstance = isInstance(TYPES_NAMES.Either)
Either.isOfType = isOfType(TYPES_NAMES.Either)

var Reader = root.Reader = function (fn) {
var Reader = Monet.Reader = function (fn) {
return new Reader.fn.init(fn)
}

Expand Down Expand Up @@ -1191,12 +1179,12 @@
Reader.isInstance = isInstance(TYPES_NAMES.Reader)
Reader.isOfType = isOfType(TYPES_NAMES.Reader)

var Free = root.Free = {}
var Free = Monet.Free = {}

var Suspend = Free.Suspend = root.Suspend = function (functor) {
var Suspend = Free.Suspend = Monet.Suspend = function (functor) {
return new Free.fn.init(functor, true)
}
var Return = Free.Return = root.Return = function (val) {
var Return = Free.Return = Monet.Return = function (val) {
return new Free.fn.init(val, false)
}

Expand Down Expand Up @@ -1285,7 +1273,7 @@
return new Identity.fn.init(a)
}

root.Identity = Identity
Monet.Identity = Identity

Identity.of = function (a) {
return new Identity(a)
Expand Down Expand Up @@ -1330,9 +1318,6 @@
return List(this.get(), Nil)
},
toSet: function () {
if (!rootGlobalObject.Set) {
throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.')
}
return new Set(this)
}
}
Expand Down Expand Up @@ -1429,10 +1414,6 @@

function makeIterable(type) {
if (isFunction(type.prototype.toArray)) {
if (!rootGlobalObject.Symbol) {
// eslint-disable-next-line no-console
console.error(new Error('Provide polyfill or use up to date browser/node version to use "Iterable" protocol.'))
}
type.prototype[Symbol.iterator] = function () {
return this.toArray()[Symbol.iterator]()
}
Expand Down Expand Up @@ -1470,11 +1451,5 @@
decorate(Free)
decorate(Identity)

return Maybe.fromNull(rootGlobalObject)
.filter(function (rootObj) { return rootObj.useMonetGlobalObject })
.cata(function () { return assign(Monet, root) }, function (rootObj) {
assign(rootObj, root)
rootObj.Monet = Monet
return Monet
})
return Monet
}))
7 changes: 5 additions & 2 deletions test/either-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/

describe('An Either', function () {
var Either = Monet.Either
var Right = Monet.Right
var Left = Monet.Left
var sideEffectsReceiver = null

beforeEach(function () {
Expand Down Expand Up @@ -113,7 +116,7 @@ describe('An Either', function () {
it('equals to Right with the same value', function () {
expect(rightString.equals(Either.Right('abcd'))).toBe(true)
expect(rightString.equals(Either.right('abcd'))).toBe(true)
expect(Right(Just(2)).equals(Right(Just(2)))).toBe(true)
expect(Right(Monet.Just(2)).equals(Right(Monet.Just(2)))).toBe(true)
})
it('does not equal to Rights with different values or Lefts', function () {
expect(rightString.equals(Either.Left('abcd'))).toBe(false)
Expand Down Expand Up @@ -227,7 +230,7 @@ describe('An Either', function () {
it('equals to Left with the same value', function () {
expect(leftString.equals(Either.Left('error dude'))).toBe(true)
expect(leftString.equals(Either.left('error dude'))).toBe(true)
expect(Left(Just(2)).equals(Left(Just(2)))).toBe(true)
expect(Left(Monet.Just(2)).equals(Left(Monet.Just(2)))).toBe(true)
})
it('does not equal to Rights with different values or Lefts', function () {
expect(leftString.equals(Either.Left('x'))).toBeFalsy()
Expand Down
5 changes: 5 additions & 0 deletions test/free-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
describe('A Free monad', function () {
var Free = Monet.Free
var Suspend = Monet.Suspend
var Return = Monet.Return
var Identity = Monet.Identity

it('do Ken\'s simple box example', function () {
var s1 = Free.liftF(Identity(1));
var s2 = Free.liftF(Identity(2));
Expand Down
1 change: 1 addition & 0 deletions test/io-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('An IO monad', function () {
var IO = Monet.IO
var effect = IO(function () {
return 'effect';
})
Expand Down
10 changes: 10 additions & 0 deletions test/list-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
describe('An immutable list', function () {
var List = Monet.List
var Nil = Monet.Nil
var Some = Monet.Some
var None = Monet.None
var IO = Monet.IO
var Reader = Monet.Reader
var Right = Monet.Right
var Left = Monet.Left
var Success = Monet.Success
var Fail = Monet.Fail
var sideEffectsReceiver = null

function expectCalls(spiedCall, values) {
Expand Down
Loading

0 comments on commit 3660986

Please sign in to comment.