paldepind / union-type

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

publish next release #27

Closed gilligan closed 8 years ago

gilligan commented 8 years ago

I just added union-type to our codebase the other day and I quite like - I am very interested in what you have been working on in the next branch - what are your plans in regarding a new release merging next into master ? What does it take for this to be merged ? How could I help ?

davidchambers commented 8 years ago

https://github.com/paldepind/union-type/compare/master...next

gilligan commented 8 years ago

I made a fork and rebased next on master - Two failing tests that I am looking into now ...

gilligan commented 8 years ago

I am afraid I am stuck. After my rebase rawCase looks like this :

function rawCase(type, cases, value, arg) {
  var name = value.name in cases ? value.name : '_';
  if (process.env.NODE_ENV !== 'production') {
    if (!type.isPrototypeOf(value)) throw new Error('Non-exhaustive patterns in a function');
    if (!(name in cases)) {
      throw new Error('unhandled value passed to case');
    }
  }
  return cases[name].apply(undefined, arg !== undefined ? valueToArray(value).concat([arg]) : value);
}

What fails now is the test does not extract fields when matching _ - Trying to make sense of the code :)

edit: I guess this might work then :

function rawCase(type, cases, value, arg) {
  var name = value.name in cases ? value.name : '_';
  if (process.env.NODE_ENV !== 'production') {
    if (!type.isPrototypeOf(value)) throw new Error('Non-exhaustive patterns in a function');
    if (!(name in cases)) {
      throw new Error('unhandled value passed to case');
    }
  }
  if (name === '_') return arg;
  return cases[name].apply(undefined, arg !== undefined ? valueToArray(value).concat([arg]) : value);
}
gilligan commented 8 years ago

https://github.com/gilligan/union-type/tree/reintegrate all tests passing now.

gilligan commented 8 years ago

Created a PR. I would really love to use the new features. Please let me know what needs to be done for this to go forward ;)