Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FP function generation (closes #253) #393

Merged
merged 12 commits into from Feb 27, 2017
Merged

Add FP function generation (closes #253) #393

merged 12 commits into from Feb 27, 2017

Conversation

leshakoss
Copy link
Contributor

No description provided.

@leshakoss leshakoss changed the title (WIP) Add FP function generation on npm release (closes #253) Add FP function generation (closes #253) Jan 14, 2017
.concat('')
.join('\n')

const fpFnWithOptionsLines = ['// This file is generated automatically. Please don\'t change it.']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please point to this script in the comment (here and everywhere in such comments). Also Please,

docs/Options.js Outdated
* Specifies, which way to round partial units. Options: 'floor', 'ceil', 'round'
* @property {'s'|'m'|'h'|'d'|'M'|'Y'} [unit] - used by `distanceInWordsStrict`.
* If specified, will force a unit
* @property {'floor'|'ceil'|'round'} [partialMethod='floor'] - used by `distanceInWordsStrict`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 {0 | 1 | 2} has inner spacing, while {'floor'|'ceil'|'round'} doesn't. Let's make it consistent.

.concat('')
.concat(`var ${name}WithOptions = convertToFpWithOptions(fn, ${arity})`)
.concat('')
.concat(`module.exports = ${name}WithOptions`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's generate ES6 versions here, ES5 versions will be compiled by Babel.

@leshakoss
Copy link
Contributor Author

@mattlewis92 hello, could you please give me a hand here? I tried to make TypeScript typings for FP functions #253 but I don't know how to do it correctly

@mattlewis92
Copy link
Member

Happy to help 😄 I can't see from the diff what issues you're facing, can you give me a specific example of where you're running into trouble?

@leshakoss
Copy link
Contributor Author

leshakoss commented Jan 18, 2017

@mattlewis92 I generated a bunch of FP functions like these: 39af0f2#diff-0777f5ac1c488eba0e7fe9c0d2629658R1

They come in two variations, with options and without them:

// regular function, from ./src/add_days
addDays(date, amount, options)

// FP function, from ./src/fp/addDays:
addDays(amount)(date)

// FP function with options, from ./src/fp/addDaysWithOptions
addDaysWithOptions(options)(amount)(date)

Basically, they are the same as regular functions but the order of arguments is reversed and arguments are curried:

import _addDays from 'date-fns/add_days'
const addDays = (b) => (a) => _addDays(a, b)
const addDaysWithOptions = (options) => (b) => (a) => _addDays(a, b, options)

I wanted to generate TypeScript typings for them:
a4cfe8f#diff-9b9d1a591a5fff70b4e5f52e2dbf48cbR937
But I don't really know if I did it correctly and if there is some idiomatic way to make typings for them. (I tried to check it in online TypeScript playground, but I don't think there's a way to check how separate typing files like ./typings.d.ts work there. I don't know much about TypeScript module declarations and namespaces and stuff). Could you please help me with it?

@mattlewis92
Copy link
Member

Ah ok, maybe adding an e2e typescript test would be a good idea, similar to how definitely typed works?

@leshakoss
Copy link
Contributor Author

leshakoss commented Jan 18, 2017 via email

@mattlewis92
Copy link
Member

So every lib on definitely typed has the typings and then a test file that uses the typings in some example usage. The idea is that if tsc can compile them then the typings are valid. For example: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/webpack

@leshakoss
Copy link
Contributor Author

@mattlewis92 Oh, gotcha. I'll think about it. Well, for now, is

declare module 'date-fns/fp' {
  let addDays: (number) => (Date | string | number) => (Date)
  namespace addDays {}
}

declare module 'date-fns/fp/addDays' {
  import {addDays} from 'date-fns/fp'
  export = addDays
}

declare module 'date-fns/fp/addDays/index' {
  import {addDays} from 'date-fns/fp'
  export = addDays
}

is the correct TypeScript declaration for this function?

// ./src/fp/addDays
import _addDays from './../add_days/index.js'
const addDays = (b) => (a) => _addDays(a, b)
export default addDays

or should it be declared some other way? (like

declare module 'date-fns/fp' {
  function addDays (number): ((Date | string | number) => (Date))
  namespace addDays {}
}

or something like this, I don't know)

@mattlewis92
Copy link
Member

Uh I'm not too sure off the top of my head, I will get back to you tomorrow 😃

@leshakoss
Copy link
Contributor Author

@mattlewis92 thanks 🙂

Copy link
Member

@kossnocorp kossnocorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make a(1)(2, 3) possible.

@griffinmichl
Copy link

I was just typing up this exact feature request when I came across this PR.

Thanks for the awesome work y'all are doing! Any idea when v2 will drop?

Copy link
Member

@kossnocorp kossnocorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱😍:shipit:

@leshakoss leshakoss merged commit b88d382 into v2 Feb 27, 2017
@leshakoss leshakoss deleted the 253-fp branch February 27, 2017 11:27
leshakoss added a commit that referenced this pull request Feb 28, 2017
* Add FP function generation

* Modify build_index to build FP index

* Add FP typings generator

* Regenerate docs, indices, typings and FP

* Add FP doc

* Add FP CHANGELOG.md entry

* Add lodash-fp example

* Add FP examples

* Remove unused phantomjs-prebuilt

* Add FP tests

* Fix style

* Add ECMAScript Modules documentation article
leshakoss added a commit that referenced this pull request Mar 28, 2017
* Add FP function generation

* Modify build_index to build FP index

* Add FP typings generator

* Regenerate docs, indices, typings and FP

* Add FP doc

* Add FP CHANGELOG.md entry

* Add lodash-fp example

* Add FP examples

* Remove unused phantomjs-prebuilt

* Add FP tests

* Fix style

* Add ECMAScript Modules documentation article
leshakoss added a commit that referenced this pull request Apr 14, 2017
* Add FP function generation

* Modify build_index to build FP index

* Add FP typings generator

* Regenerate docs, indices, typings and FP

* Add FP doc

* Add FP CHANGELOG.md entry

* Add lodash-fp example

* Add FP examples

* Remove unused phantomjs-prebuilt

* Add FP tests

* Fix style

* Add ECMAScript Modules documentation article
leshakoss added a commit that referenced this pull request May 20, 2017
* Add FP function generation

* Modify build_index to build FP index

* Add FP typings generator

* Regenerate docs, indices, typings and FP

* Add FP doc

* Add FP CHANGELOG.md entry

* Add lodash-fp example

* Add FP examples

* Remove unused phantomjs-prebuilt

* Add FP tests

* Fix style

* Add ECMAScript Modules documentation article
leshakoss added a commit that referenced this pull request May 20, 2017
* Add FP function generation

* Modify build_index to build FP index

* Add FP typings generator

* Regenerate docs, indices, typings and FP

* Add FP doc

* Add FP CHANGELOG.md entry

* Add lodash-fp example

* Add FP examples

* Remove unused phantomjs-prebuilt

* Add FP tests

* Fix style

* Add ECMAScript Modules documentation article
kossnocorp pushed a commit that referenced this pull request Jun 20, 2017
* Add FP function generation

* Modify build_index to build FP index

* Add FP typings generator

* Regenerate docs, indices, typings and FP

* Add FP doc

* Add FP CHANGELOG.md entry

* Add lodash-fp example

* Add FP examples

* Remove unused phantomjs-prebuilt

* Add FP tests

* Fix style

* Add ECMAScript Modules documentation article
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants