paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

Version 0.4.0 changed the way paramless functions are called #60

Closed rmoliva closed 7 years ago

rmoliva commented 7 years ago

Hello

We are experiencing a disturbing issue: When I upgraded my union-type project dependencies from 0.3.3 to 0.4.0 all of the type functions that have no parameters starts to fall. Sorry for my English, I will try to explain it with code. You have the following union-type definition and its associated case functions:

var Action = Type({Incr: [], Add: [Number]});
var value = 1;
var changeValue = function(action, value) {
  return Action.case({
    Incr: function() { return value + 1; },
    Add: function(x) { return value + x; },
  }, action);
};

In version 0.3.3 you can do the following without problem:

value = changeValue(Action.Add(6), value);
console.log(value); //=> 7
value = changeValue(Action.Incr(), value);
console.log(value); //=> 8

But in version 0.4.0 you get an exception with the Action.Incr() call. You have to pass the function directly:

value = changeValue(Action.Add(6), value);
console.log(value); //=> 7
value = changeValue(Action.Incr, value);
console.log(value); //=> 8
value = changeValue(Action.Incr(), value);
console.log(value); //=> TypeError: Action.Incr is not a function

It is not a great issue but leads us to a change and revision all of our previous code.

I also would like to thanks @paldepind for his great software (union-type, flyd, snabbdom, etc.). We thoroughly use it in our company with great success.

Roberto M. Oliva

davidchambers commented 7 years ago

I'm sorry to breaking change caused you inconvenience, @rmoliva. I believe it's an improvement, though. See #54 for the brief discussion which led to the change.

rmoliva commented 7 years ago

Thanks @davidchambers. I missed that issue. That explain the breaking change.