Skip to content

Commit 7ad7ab1

Browse files
committed
Minor tweaks
1 parent dc05252 commit 7ad7ab1

File tree

9 files changed

+30
-42
lines changed

9 files changed

+30
-42
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "jshint src && jscs src && psa \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" --censor-lib --strict",
6-
"test": "psa \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" \"examples/**/*.purs\" --censor-lib --strict"
5+
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
6+
"test": "pulp build -I examples --censor-lib --strict"
77
},
88
"devDependencies": {
9-
"jscs": "^2.8.0",
10-
"jshint": "^2.9.1",
11-
"pulp": "^8.2.0",
12-
"purescript-psa": "^0.3.8",
13-
"rimraf": "^2.5.0"
9+
"jscs": "^3.0.7",
10+
"jshint": "^2.9.2",
11+
"pulp": "^9.0.1",
12+
"purescript-psa": "^0.3.9",
13+
"rimraf": "^2.5.4"
1414
}
1515
}

src/Data/Foreign.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global exports */
22
"use strict";
33

4-
// module Data.Foreign
5-
64
// jshint maxparams: 3
75
exports.parseJSONImpl = function (left, right, str) {
86
try {
@@ -11,8 +9,8 @@ exports.parseJSONImpl = function (left, right, str) {
119
return left(e.toString());
1210
}
1311
};
14-
1512
// jshint maxparams: 1
13+
1614
exports.toForeign = function (value) {
1715
return value;
1816
};

src/Data/Foreign.purs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
-- | data.
33

44
module Data.Foreign
5-
( Foreign()
5+
( Foreign
66
, ForeignError(..)
77
, Prop(..)
8-
, F()
8+
, F
99
, parseJSON
1010
, toForeign
1111
, unsafeFromForeign
@@ -57,12 +57,8 @@ instance showForeignError :: Show ForeignError where
5757
show (ErrorAtProperty prop e) = "Error at property " <> show prop <> ": " <> show e
5858
show (JSONError s) = "JSON error: " <> s
5959

60-
instance eqForeignError :: Eq ForeignError where
61-
eq (TypeMismatch a b) (TypeMismatch a' b') = a == a' && b == b'
62-
eq (ErrorAtIndex i e) (ErrorAtIndex i' e') = i == i' && e == e'
63-
eq (ErrorAtProperty p e) (ErrorAtProperty p' e') = p == p' && e == e'
64-
eq (JSONError s) (JSONError s') = s == s'
65-
eq _ _ = false
60+
derive instance eqForeignError :: Eq ForeignError
61+
derive instance ordForeignError :: Ord ForeignError
6662

6763
-- | An error monad, used in this library to encode possible failure when
6864
-- | dealing with foreign data.
@@ -140,6 +136,9 @@ readArray :: Foreign -> F (Array Foreign)
140136
readArray value | isArray value = pure $ unsafeFromForeign value
141137
readArray value = Left (TypeMismatch "array" (tagOf value))
142138

139+
-- | A key/value pair for an object to be written as a `Foreign` value.
143140
newtype Prop = Prop { key :: String, value :: Foreign }
144141

142+
-- | Constructs a JavaScript `Object` value (typed as `Foreign`) from an array
143+
-- | of `Prop`s.
145144
foreign import writeObject :: Array Prop -> Foreign

src/Data/Foreign/Class.purs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
module Data.Foreign.Class
44
( class IsForeign
5-
, class AsForeign
6-
, (.=)
75
, read
86
, readJSON
97
, readWith
108
, readProp
9+
, class AsForeign
1110
, write
12-
, writeProp
11+
, writeProp, (.=)
1312
) where
1413

1514
import Prelude
@@ -51,7 +50,7 @@ instance numberIsForeign :: IsForeign Number where
5150
instance intIsForeign :: IsForeign Int where
5251
read = readInt
5352

54-
instance arrayIsForeign :: (IsForeign a) => IsForeign (Array a) where
53+
instance arrayIsForeign :: IsForeign a => IsForeign (Array a) where
5554
read value = readArray value >>= readElements
5655
where
5756
readElements :: Array Foreign -> F (Array a)
@@ -60,21 +59,21 @@ instance arrayIsForeign :: (IsForeign a) => IsForeign (Array a) where
6059
readElement :: Int -> Foreign -> F a
6160
readElement i value = readWith (ErrorAtIndex i) value
6261

63-
instance nullIsForeign :: (IsForeign a) => IsForeign (Null a) where
62+
instance nullIsForeign :: IsForeign a => IsForeign (Null a) where
6463
read = readNull read
6564

66-
instance undefinedIsForeign :: (IsForeign a) => IsForeign (Undefined a) where
65+
instance undefinedIsForeign :: IsForeign a => IsForeign (Undefined a) where
6766
read = readUndefined read
6867

69-
instance nullOrUndefinedIsForeign :: (IsForeign a) => IsForeign (NullOrUndefined a) where
68+
instance nullOrUndefinedIsForeign :: IsForeign a => IsForeign (NullOrUndefined a) where
7069
read = readNullOrUndefined read
7170

7271
-- | Attempt to read a data structure from a JSON string
73-
readJSON :: forall a. (IsForeign a) => String -> F a
72+
readJSON :: forall a. IsForeign a => String -> F a
7473
readJSON json = parseJSON json >>= read
7574

7675
-- | Attempt to read a foreign value, handling errors using the specified function
77-
readWith :: forall a e. (IsForeign a) => (ForeignError -> e) -> Foreign -> Either e a
76+
readWith :: forall a e. IsForeign a => (ForeignError -> e) -> Foreign -> Either e a
7877
readWith f value = either (Left <<< f) Right (read value)
7978

8079
-- | Attempt to read a property of a foreign value at the specified index
@@ -105,19 +104,19 @@ instance numberAsForeign :: AsForeign Number where
105104
instance intAsForeign :: AsForeign Int where
106105
write = toForeign
107106

108-
instance arrayAsForeign :: (AsForeign a) => AsForeign (Array a) where
107+
instance arrayAsForeign :: AsForeign a => AsForeign (Array a) where
109108
write = toForeign <<< map write
110109

111-
instance nullAsForeign :: (AsForeign a) => AsForeign (Null a) where
110+
instance nullAsForeign :: AsForeign a => AsForeign (Null a) where
112111
write (Null a) = maybe writeNull write a
113112

114-
instance undefinedAsForeign :: (AsForeign a) => AsForeign (Undefined a) where
113+
instance undefinedAsForeign :: AsForeign a => AsForeign (Undefined a) where
115114
write (Undefined a) = maybe writeUndefined write a
116115

117-
instance nullOrUndefinedAsForeign :: (AsForeign a) => AsForeign (NullOrUndefined a) where
116+
instance nullOrUndefinedAsForeign :: AsForeign a => AsForeign (NullOrUndefined a) where
118117
write (NullOrUndefined a) = write (Null a)
119118

120119
infixl 8 writeProp as .=
121120

122-
writeProp :: forall a. (AsForeign a) => String -> a -> Prop
121+
writeProp :: forall a. AsForeign a => String -> a -> Prop
123122
writeProp k v = Prop { key: k, value: write v }

src/Data/Foreign/Index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global exports */
22
"use strict";
33

4-
// module Data.Foreign.Index
5-
64
// jshint maxparams: 4
75
exports.unsafeReadPropImpl = function (f, s, key, value) {
86
return value == null ? f : s(value[key]);

src/Data/Foreign/Index.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import Data.Either (Either(..))
1717
import Data.Foreign (Foreign, F, ForeignError(..), typeOf, isUndefined, isNull)
1818
import Data.Function.Uncurried (Fn2, runFn2, Fn4, runFn4)
1919

20-
-- | This type class identifies types wich act like _property indices_.
20+
-- | This type class identifies types that act like _property indices_.
2121
-- |
22-
-- | The canonical instances are for `String`s and `Number`s.
22+
-- | The canonical instances are for `String`s and `Int`s.
2323
class Index i where
2424
ix :: Foreign -> i -> F Foreign
2525
hasProperty :: i -> Foreign -> Boolean

src/Data/Foreign/Keys.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global exports */
22
"use strict";
33

4-
// module Data.Foreign.Keys
5-
64
exports.unsafeKeys = Object.keys || function (value) {
75
var keys = [];
86
for (var prop in value) {

src/Data/Foreign/Null.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/* global exports */
22
"use strict";
33

4-
// module Data.Foreign.Null
5-
64
exports.writeNull = null;

src/Data/Foreign/Undefined.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/* global exports */
22
"use strict";
33

4-
// module Data.Foreign.Undefined
5-
64
exports.writeUndefined = undefined;

0 commit comments

Comments
 (0)