Skip to content

Commit

Permalink
Adds missing docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
robotlolita committed Jun 25, 2017
1 parent 45d40fb commit 31e135e
Show file tree
Hide file tree
Showing 17 changed files with 722 additions and 36 deletions.
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ compile-documentation:
clean:
rm -rf packages/base/build packages/base/dist
rm -rf test/build
rm -rf annotations/build docs/api
rm -rf annotations/build

.PHONY: _prepare-test
_prepare-test: clean compile compile-annotated compile-test
Expand Down Expand Up @@ -141,3 +141,22 @@ tools:
cd tools/static-docs && npm install && make build && npm link
npm link metamagical-static-docs

.PHONY: release-base
release-base: lint test-all test-browser # test-sauce
$(eval VERSION := $(shell node -pe "require('./packages/base/package.json').version"))
$(MAKE) clean
$(MAKE) compile
$(MAKE) compile-annotated
$(MAKE) bundle
$(MAKE) compile-documentation
$(MAKE) _documentation
cd docs && bundle exec jekyll build
mkdir -p packages/base/releases/
rm -rf packages/base/releases/$(VERSION)
cp -R packages/base/build packages/base/releases/$(VERSION)
cp -R docs/_site packages/base/releases/$(VERSION)/docs
cp -R packages/base/dist packages/base/releases/$(VERSION)/dist
cp packages/base/package.json packages/base/releases/$(VERSION)/package.json
cp packages/base/CHANGELOG.md packages/base/releases/$(VERSION)/CHANGELOG.md
cd packages/base/releases/$(VERSION) && zip -r ../folktale-base-$(VERSION).zip *
# cd packages/base/releases/$(VERSION) && npm publish
6 changes: 4 additions & 2 deletions docs/_data/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
- v2.0.0/release-notes
- v2.0.0/download
- v2.0.0/getting-started
- v2.0.0/api
- url: /api/v2.0.0/en/folktale.html
title: API reference
- v2.0.0/changelog
- v2.0.0/known-issues

Expand Down Expand Up @@ -46,4 +47,5 @@

- title: Legacy
docs:
- legacy/1.x
- url: http://folktalegithubio.readthedocs.io/en/latest/
title: Folktale 1.x
5 changes: 0 additions & 5 deletions docs/_docs/v2.0.0/api.md

This file was deleted.

326 changes: 324 additions & 2 deletions docs/_docs/v2.0.0/changelog.md

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions docs/_docs/v2.0.0/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,171 @@ title: Installing
prev_doc: v2.0.0/release-notes
next_doc: v2.0.0/getting-started
---

The recommended way of getting Folktale is through [npm][]. If you don't have Node installed yet, you should [download a binary from the official website](https://nodejs.org/en/) or use an installer like [nvm](https://github.com/creationix/nvm).

> **NOTE**
> Folktale requires Node 6.x+ for its development tools, but you can use a prebuilt version of Folktale in Node 4.x+.
To install Folktale using npm, run the following in your command line:

$ npm install folktale


## Contents
{:.no_toc}

* TOC
{:toc}


## Folktale in Node.js

Node.js has native support for the CommonJS module system, which Folktale uses, thus in order to use Folktale you just `require` it:

```js
const folktale = require('folktale');

folktale.core.lambda.identity(1); // ==> 1
```


## Folktale in Electron / nw.js

Like Node.js, [Electron](https://electron.atom.io/) and [nw.js](https://nwjs.io/) have native support for the CommonJS module system, so you load Folktale using `require`:

```js
const folktale = require('folktale');

folktale.core.lambda.identity(1); // ==> 1
```

## Folktale in the Browser

Browsers don't have native support for CommonJS modules. We still recommend using a module system (like [Browserify][] or [WebPack][]) and bundling your modules to distribute your application. This allows you to only load the parts of Folktale that you use, reducing the amount of data you have to send to your users.


### Using Browserify

First install Browserify from npm (you should have a package.json describing your application's dependencies):

$ npm install browserify --save-dev

Then install Folktale through npm as well:

$ npm install folktale --save

Ideally, require only the Folktale modules you'll be using. This helps keeping the overall size smaller. For example, if you're using only the `Maybe` and `compose` functions, don't load the library's entry-point, just those modules:

```js
const Maybe = require('folktale/data/maybe');
const compose = require('folktale/core/lambda/compose');

const inc = (x) => x + 1;
const double = (x) => x * 2;

Maybe.Just(1).map(compose(inc, double));
// ==> Maybe.Just(4)
```

To compile your application, run `browserify` on your entry-point module (you run this from the root of your project, where your `package.json` is located at):

$ ./node_modules/.bin/browserify index.js > my-app.js

Finally, load `my-app.js` in your webpage. This file will contain all of the modules you've `require`d in your `index.js` file:

```html
<!DOCTYPE html>
<html>
<head>(...)</head>
<body>
(...)
<script src="/path/to/my-app.js"></script>
</body>
</html>
```

For more information about Browserify, [check Browserify's website](http://browserify.org/).


### Using WebPack

First install WebPack from npm (you should have a package.json describing your application's dependencies):

$ npm install webpack --save-dev

Then install Folktale through npm as well:

$ npm install folktale --save

Ideally, require only the Folktale modules you'll be using. This helps keeping the overall size smaller. For example, if you're using only the `Maybe` and `compose` functions, don't load the library's entry-point, just those modules:

```js
const Maybe = require('folktale/data/maybe');
const compose = require('folktale/core/lambda/compose');

const inc = (x) => x + 1;
const double = (x) => x * 2;

Maybe.Just(1).map(compose(inc, double));
// ==> Maybe.Just(4)
```

Create a `webpack.config.js` in your project's root directory, containing instructions for how WebPack should build your application:

```js
module.exports = {
entry: './index.js',
output: {
filename: 'my-app.js'
}
};
```

Finally, load `my-app.js` in your webpage. This file will contain all of the modules you've `require`d in your `index.js` file:

```html
<!DOCTYPE html>
<html>
<head>(...)</head>
<body>
(...)
<script src="/path/to/my-app.js"></script>
</body>
</html>
```

For more information about WebPack, [check WebPack's website](https://webpack.js.org/).


### Using Folktale without a module system

While the recommended way of using Folktale is with a module system, it's possible to use it without one as well. The drawback of not using a module system is that your website will have to ship the entire Folktale library to your users, even if you don't use all of its features.

To use a prebuilt version, first, download one of the [prebuilt releases](https://github.com/origamitower/folktale/releases) on GitHub. Unpack the distribution file and add the `dist/folktale.min.js` or `dist/folktale.js` file to your website. Reference this file in your HTML like any other JavaScript file:

```html
<!DOCTYPE html>
<html>
<head>(...)</head>
<body>
(...)
<script src="/path/to/folktale.min.js"></script>
</body>
</html>
```

In your JavaScript code, the Folktale library will be available through the global variable `folktale`, **unless you're using a CommonJS or AMD module system in your webpage**:

```js
folktale.core.lambda.identity(1);
// ==> 1
```

> **NOTE**:
> If you're using a module system in your webpage (for example, AMD in Dojo or Require.js), then Folktale will be available through that module system under `folktale`.

[npm]: https://www.npmjs.com
[Browserify]: http://browserify.org/
[WebPack]: https://webpack.github.io/
5 changes: 3 additions & 2 deletions docs/_docs/v2.0.0/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Getting started
prev_doc: v2.0.0/download
next_doc: v2.0.0/api
---
next_doc: v2.0.0/changelog
---

5 changes: 4 additions & 1 deletion docs/_docs/v2.0.0/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
title: Known issues
prev_doc: v2.0.0/changelog
next_doc: v2.0.0/migrating
---
---

- [`union(typeId, patterns)` fails in Node 5.x](https://github.com/origamitower/folktale/issues/47) (v8 4.6.85.x) due to a bug in the optimising compiler. This bug has since been fixed (Node 6+ versions are okay), and does not affect older v8 versions (Node 4.x is also okay).

109 changes: 108 additions & 1 deletion docs/_docs/v2.0.0/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,111 @@
title: Release notes
prev_doc: v2.0.0
next_doc: v2.0.0/download
---
---

Folktale v2.0.0 is the result of more than one year of work in constructing and documenting a coherent basis for functional programming in JavaScript. There's a lot left to be done, but this release is an important step in that direction.

This document describes the most noteworthy changes, see the [full changelog]({% link _docs/v2.0.0/changelog.md %}) for all the changes.


## Contents
{:.no_toc}

* TOC
{:toc}


## Highlights

- [Moving away from currying](#moving-away-from-currying)
— this release prefers leveraging native JavaScript constructs instead of
currying, which does not compose well with most JavaScript (variadic) APIs.

- [Simplified Union types](#simplified-union-types)
— the new `adt/union` module allows constructing union types in an easy way.

- [A more robust Task API](#a-more-robust-task-api)
— the new Task API includes resource handling at the core of its model, and
tries to mitigate the possibility of race conditions as much as possible.


### Moving away from currying

Folktale 1 relied heavily on currying. [This caused problems when interacting with native JavaScript functions](https://github.com/origamitower/folktale/issues/38). The new library aims to interact better with JavaScript, so native JavaScript constructs are preferred.

Some functions in the new Folktale library are still curried by default. `compose` is a good example. It takes two functions, and returns a new one that takes an argument. The major difference is that there's no automatic unrolling happening.

{% highlight js %}
// Folktale 1.x
const compose = curry(3, (f, g, x) => ...);

compose(f, g, x, y) === compose(f)(g)(x)(y);
compose(f, g, x) === compose(f)(g)(x);
compose(f, g)(x) === compose(f)(g)(x);
compose(f)(g)(x) === compose(f)(g)(x);


// Folktale 2.x+
const compose = (f, g) => (x) => ...;

compose(f, g, x, y) === compose(f, g);
compose(f, g, x) === compose(f, g);
compose(f, g)(x) === compose(f, g)(x);
compose(f)(g)(x) === compose(f)(g)(x); // an error
{% endhighlight %}


More details on currying can be seen in the [`curry() documentation`](/api/v2.0.0/en/folktale.core.lambda.curry.curry.html).


### Simplified Union types

JavaScript does not have native support for tagged unions. This is one of the core features of functional programming. Unions help programmers model possibilities, and often help defining recursive procedures.

Folktale 2 helps with this by providing a new [`union`](/api/v2.0.0/en/folktale.adt.union.html) module. This module allows creating union types by listing the possibilities and their fields.

{% highlight js %}
const { union } = require('folktale/adt/union');

const List = union('List', {
Empty(){ },

Cons(value, rest) {
return { value, rest };
}
});
{% endhighlight %}


The union module also provides default features for these data structures. The derivation feature allows users to share extensions to these defaults. More details on this module can be found in the [union documentation](/api/v2.0.0/en/folktale.adt.union.html).


### A more robust Task API

Folktale 1 introduced a concept of Tasks to help with asynchronous computations. However, the API made composition difficult, and increased the likelihood of hitting race conditions and other edge cases.

Folktale 2 includes a full redesign of the Task API, focused on ease of use, compositionality and robustness. Thew new Task model now fully supports asynchronous resource lifecycle handling, concurrent composition, and task cancellation.

The [Task documentation](/api/v2.0.0/en/folktale.concurrency.html) describes this in details.



## Acknowledgements

A huge thank you to everyone who contributed to improving Folktale, by reporting errors, sending feedback, talking about it, sending patches, etc.

A special thank you to:

- [@rpearce](https://github.com/rpearce): Converting nodebacks to Tasks (PR [#116](https://github.com/origamitower/folktale/pull/116))
- [@boris-marinov](https://github.com/boris-marinov):
- Porting [Either/Result](https://github.com/origamitower/folktale/pull/6) and [Validation](https://github.com/origamitower/folktale/pull/22);
- Writing most of the [data conversions](https://github.com/origamitower/folktale/pull/24) and [generic fantasy-land functions](https://github.com/origamitower/folktale/pull/37);
- Writing the [Equality](https://github.com/origamitower/folktale/pull/10), [Serialization](https://github.com/origamitower/folktale/pull/15), and [DebugRepresentation](https://github.com/origamitower/folktale/pull/12) derivations;
- Helping with all the test infrastructure and providing valuable feedback on API design, which is greatly appreciated even if it can't be mapped to a specific pull request :)
- [@amilajack](https://github.com/amilajack): Updating dependencies (PR [#33](https://github.com/origamitower/folktale/pull/33))
- [@sotojuan](https://github.com/sotojuan): Making our npm package less bloated (PR [#34](https://github.com/origamitower/folktale/pull/34))
- [@syaiful6](https://github.com/syaiful6): Removing a duplicated Setoid derivation (PR [#57](https://github.com/origamitower/folktale/pull/57))
- [@degroote22](https://github.com/degroote22): Fixing some typos in the docs (PR [#59](https://github.com/origamitower/folktale/pull/59))
- [@RossJHagan](https://github.com/RossJHagan): Fixing some formatting issues with the curry docs (PR [#72](https://github.com/origamitower/folktale/pull/72))
- [@justin-calleja](https://github.com/justin-calleja): Documentation improvements (PRs [#94](https://github.com/origamitower/folktale/pull/94), [#103](https://github.com/origamitower/folktale/pull/103), and [#107](https://github.com/origamitower/folktale/pull/107))
- [@diasbruno](https://github.com/diasbruno): Implementing Semigroup and Monoid for Maybe (PR [#125](https://github.com/origamitower/folktale/pull/125))
Loading

0 comments on commit 31e135e

Please sign in to comment.