Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
rename spec to patch
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Feb 8, 2016
1 parent bf01b0c commit 595c26a
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ A.define(t.struct({
You can update an immutable instance with the provided `update` function:

```js
MyTcombType.update(instance, spec)
MyTcombType.update(instance, patch)
```

The following commands are compatible with the [Facebook Immutability Helpers](http://facebook.github.io/react/docs/update.html):
Expand Down Expand Up @@ -750,7 +750,7 @@ Immutability helper for POJOs.
**Signature**

```js
update(instance: Object, spec: Object) => Object
update(instance: Object, patch: Object) => Object
```

**Example**
Expand All @@ -763,7 +763,7 @@ t.update(x, { a: { $set: 2 } }); // => { a: 2 }, x is untouched
**Note**. You can change the default behaviour overriding the `t.update` function:

```js
t.update = function (instance, spec) {
t.update = function (instance, patch) {
// your implementation here
};
```
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ declare module Tcomb {
interface UnshiftCommand { $unshift: Array<any>; }
interface MergeCommand { $merge: Object; }
type Command = ApplyCommand | PushCommand | RemoveCommand | SetCommand | SpliceCommand | SwapCommand | UnshiftCommand | MergeCommand;
type UpdateSpec = Command | {[key: string]: UpdateSpec};
type Update<T> = (instance: T, spec: UpdateSpec) => T;
type UpdatePatch = Command | {[key: string]: UpdatePatch};
type Update<T> = (instance: T, spec: UpdatePatch) => T;

type Constructor<T> = Type<T> | Function;

Expand Down
4 changes: 2 additions & 2 deletions lib/dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function dict(domain, codomain, name) {
return true;
};

Dict.update = function (instance, spec) {
return Dict(assert.update(instance, spec));
Dict.update = function (instance, patch) {
return Dict(assert.update(instance, patch));
};

return Dict;
Expand Down
4 changes: 2 additions & 2 deletions lib/intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function intersection(types, name) {
});
};

Intersection.update = function (instance, spec) {
return Intersection(assert.update(instance, spec));
Intersection.update = function (instance, patch) {
return Intersection(assert.update(instance, patch));
};

return Intersection;
Expand Down
4 changes: 2 additions & 2 deletions lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function list(type, name) {
});
};

List.update = function (instance, spec) {
return List(assert.update(instance, spec));
List.update = function (instance, patch) {
return List(assert.update(instance, patch));
};

return List;
Expand Down
4 changes: 2 additions & 2 deletions lib/refinement.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function refinement(type, predicate, name) {
return is(x, type) && predicate(x);
};

Refinement.update = function (instance, spec) {
return Refinement(assert.update(instance, spec));
Refinement.update = function (instance, patch) {
return Refinement(assert.update(instance, patch));
};

return Refinement;
Expand Down
4 changes: 2 additions & 2 deletions lib/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ function struct(props, name) {
return x instanceof Struct;
};

Struct.update = function (instance, spec) {
return new Struct(assert.update(instance, spec));
Struct.update = function (instance, patch) {
return new Struct(assert.update(instance, patch));
};

Struct.extend = function (structs, name) {
Expand Down
4 changes: 2 additions & 2 deletions lib/tuple.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function tuple(types, name) {
});
};

Tuple.update = function (instance, spec) {
return Tuple(assert.update(instance, spec));
Tuple.update = function (instance, patch) {
return Tuple(assert.update(instance, patch));
};

return Tuple;
Expand Down
4 changes: 2 additions & 2 deletions lib/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ function union(types, name) {
}
};

Union.update = function (instance, spec) {
return Union(assert.update(instance, spec));
Union.update = function (instance, patch) {
return Union(assert.update(instance, patch));
};

return Union;
Expand Down
12 changes: 6 additions & 6 deletions lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ function getShallowCopy(x) {
return x;
}

function update(instance, spec) {
function update(instance, patch) {

if (process.env.NODE_ENV !== 'production') {
assert(isObject(spec), function () { return 'Invalid argument spec ' + assert.stringify(spec) + ' supplied to function update(instance, spec): expected an object containing commands'; });
assert(isObject(patch), function () { return 'Invalid argument patch ' + assert.stringify(patch) + ' supplied to function update(instance, patch): expected an object containing commands'; });
}

var value = getShallowCopy(instance);
var isChanged = false;
for (var k in spec) {
if (spec.hasOwnProperty(k)) {
for (var k in patch) {
if (patch.hasOwnProperty(k)) {
if (update.commands.hasOwnProperty(k)) {
value = update.commands[k](spec[k], value);
value = update.commands[k](patch[k], value);
isChanged = true;
}
else {
var newValue = update(value[k], spec[k]);
var newValue = update(value[k], patch[k]);
isChanged = isChanged || ( newValue !== value[k] );
value[k] = newValue;
}
Expand Down
2 changes: 1 addition & 1 deletion test/dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('t.dict(domain, codomain, [name])', function () {

});

describe('update(instance, spec)', function () {
describe('update(instance, patch)', function () {

it('should return a new instance', function () {
var Dictionary = t.dict(t.String, t.String);
Expand Down
2 changes: 1 addition & 1 deletion test/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('t.list(type, [name])', function () {

});

describe('update(instance, spec)', function () {
describe('update(instance, patch)', function () {

it('should return a new instance', function () {
var ListOfStrings = t.list(t.String);
Expand Down
2 changes: 1 addition & 1 deletion test/refinement.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('t.refinement(type, predicate, [name])', function () {

});

describe('update(instance, spec)', function () {
describe('update(instance, patch)', function () {

var Type = t.refinement(t.String, function (s) { return s.length > 2; });
var instance = Type('abc');
Expand Down
2 changes: 1 addition & 1 deletion test/tuple.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('t.tuple(types, [name])', function () {

});

describe('update(instance, spec)', function () {
describe('update(instance, patch)', function () {

it('should return a new instance', function () {
var Tuple = t.tuple([t.String, t.Number]);
Expand Down
2 changes: 1 addition & 1 deletion test/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('t.union(types, [name])', function () {

});

describe('update(instance, spec)', function () {
describe('update(instance, patch)', function () {

it('should update the right instance', function () {
var circle = Shape.update({ center: { x: 0, y: 0 }, radius: 10 }, { radius: { $set: 15 } });
Expand Down
6 changes: 3 additions & 3 deletions test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var assert = require('assert');
var t = require('../index');
var throwsWithMessage = require('./util').throwsWithMessage;

describe('t.update(instance, spec)', function () {
describe('t.update(instance, patch)', function () {

var update = t.update;
var Tuple = t.tuple([t.String, t.Number]);
Expand All @@ -14,10 +14,10 @@ describe('t.update(instance, spec)', function () {
y: t.Number
});

it('should throw if spec is invalid', function () {
it('should throw if patch is invalid', function () {
throwsWithMessage(function () {
t.update({});
}, '[tcomb] Invalid argument spec undefined supplied to function update(instance, spec): expected an object containing commands');
}, '[tcomb] Invalid argument patch undefined supplied to function update(instance, patch): expected an object containing commands');
});

it('should handle $set command', function () {
Expand Down

0 comments on commit 595c26a

Please sign in to comment.