Skip to content

Commit

Permalink
build(ts): add ts target and @angular/cli integration instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Aug 24, 2017
1 parent a7898ca commit 91c36a2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ doc
# compilation targets
dist
types
targets/ts
targets/es5
targets/es2015
targets/esnext
30 changes: 27 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ for (const [target, format] of combinations([`all`, `all`])) {
gulp.task(`clean:${combo}`, ...cleanTask(target, format, combo, `targets/${target}/${format}`));
gulp.task(`bundle:${combo}`, ...bundleTask(target, format, combo, `targets/${target}/${format}`));
}
gulp.task(`build:ts`, ...copySrcTask(`ts`, ``, `ts`, `targets/ts`));
gulp.task(`clean:ts`, ...cleanTask(`ts`, ``, `ts`, `targets/ts`));
gulp.task(`bundle:ts`, ...bundleTask(`ts`, ``, `ts`, `targets/ts`));

gulp.task(`default`, [`build`]);
gulp.task(`test`, (cb) => runTaskCombos(`test`, cb));
Expand All @@ -60,6 +63,13 @@ function runTaskCombos(name, cb) {
}
combos.push(`${name}:${target}:${format}`);
}
if (name === `bundle`) {
if (~targets.indexOf(`ts`)) {
combos.push(`${name}:ts`);
} else if (targets[0] === `all` && modules[0] === `all`) {
combos.push(`${name}:ts`);
}
}
gulp.start(combos, cb);
}

Expand All @@ -83,7 +93,20 @@ function buildTask(target, format, taskName, outDir) {
: typescriptTask(target, format, taskName, outDir);
}

function copySrcTask(target, format, taskName, outDir) {
return [
[`clean:${taskName}`],
() => gulp.src([`src/**/*`]).pipe(gulp.dest(outDir))
];
}

function bundleTask(target, format, taskName, outDir) {
const nameComponents = [target];
const ext = target === `ts` ? `ts` : `js`;
const typings = target === `ts` ? `Ix.ts` : null;
if (format) {
nameComponents.push(format);
}
return [
[`build:${taskName}`],
(cb) => streamMerge([
Expand All @@ -96,10 +119,11 @@ function bundleTask(target, format, taskName, outDir) {
`license`, `keywords`, `typings`,
`repository`, `peerDependencies`
].reduce((copy, key) => (
(copy[key] = orig[key]) && copy || copy
(copy[key] = copy[key] || orig[key]) && copy || copy
), {
main: `Ix.js`,
name: `@reactivex/${orig.name}-${target}-${format}`
typings,
main: `Ix.${ext}`,
name: `@reactivex/${[orig.name, ...nameComponents].join('-')}`
}), 2),
gulp.dest(outDir),
onError
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"lerna": "2.0.0",
"version": "2.0.1",
"packages": [
"targets/ts",
"targets/es5/*",
"targets/es2015/*",
"targets/esnext/*"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"AsyncIterator"
],
"files": [
"src",
"dist",
"types",
"targets",
Expand Down
74 changes: 54 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
[![Build Status](https://travis-ci.org/ReactiveX/IxJS.svg?branch=master)](https://travis-ci.org/ReactiveX/IxJS)
# The Interactive Extensions for JavaScript (IxJS)

# The Interactive Extensions for JavaScript (IxJS)...
[![Build Status](https://travis-ci.org/ReactiveX/IxJS.svg?branch=master)](https://travis-ci.org/ReactiveX/IxJS)

*...is a set of libraries to compose synchronous and asynchronous collections and [Array#extras](http://blogs.msdn.com/b/ie/archive/2010/12/13/ecmascript-5-part-2-array-extras.aspx) style composition in JavaScript*
*IxJS is a set of libraries to compose synchronous and asynchronous collections and [Array#extras](http://blogs.msdn.com/b/ie/archive/2010/12/13/ecmascript-5-part-2-array-extras.aspx) style composition in JavaScript*

The Interactive Extensions for JavaScript (IxJS) brings the Array#extras combinators to iterables, generators, async iterables and async generators. With the introduction of the `Symbol.iterator` and generators in ES2015, and subsequent introduction of `Symbol.asyncIterator` and async generators, it became obvious we need an abstraction over these data structures for composition, querying and more.

IxJS unifies both synchronous and asynchronous pull-based collections, just as RxJS unified the world of push-based collections. RxJS is great for event-based workflows where the data can be pushed at the rate of the producer, however, IxJS is great at I/O operations where you as the consumer can pull the data when you are ready.

## Install [IxJS from npm](https://www.npmjs.com/package/ix)

```sh
npm install ix
```

(also read about how we [package IxJS](#packaging) below)

## Usage with `@angular/cli`

First, make sure you're using `@angular/cli` v1.3.2 or greater (1.3.1 has a bug that broke tsconfig's "paths" entries).

Next, install the TypeScript-only module:

```sh
npm install @reactivex/ix-ts
```

Then, add these entries to your top-level `tsconfig.json` file:

```js
{
"compilerOptions": {
"importHelpers": true, /* <-- optional but recommended */
"noEmitHelpers": true, /* <-- optional but recommended */
"downlevelIteration": true,
"paths": {
"ix/*": ["../node_modules/@reactivex/ix-ts/*"]
},
"lib": [
"esnext.asynciterable" /* <-- in addition to any other "lib" entries you have */
]
}
}

```

## `Iterable`

The `Iterable` class a way to create and compose synchronous collections much like Arrays, Maps and Sets in JavaScript using the Array#extras style using the familiar methods you are used to like `map`, `filter`, `reduce` and more.
Expand Down Expand Up @@ -86,7 +117,7 @@ const filters = require('ix/iterable/filter').filter;
const source = [1,2,3];
const results = map(
filter(
source,
source,
x => x % 2 === 0
),
x => x * x
Expand Down Expand Up @@ -233,7 +264,7 @@ const source = async function* () {

const results = map(
filter(
source(),
source(),
x => x % 2 === 0
),
x => x * x
Expand Down Expand Up @@ -316,7 +347,7 @@ for await (let item of mapped) {
}
```

In addition, you can use the specialized async methods that are suffixed with `Async`, such as `mapAsync`, `filterAsync`, `flatMapAsync` amongst others. These functions accept async functions which allow you to return a `Promise` as the result.
In addition, you can use the specialized async methods that are suffixed with `Async`, such as `mapAsync`, `filterAsync`, `flatMapAsync` amongst others. These functions accept async functions which allow you to return a `Promise` as the result.

```js
import { mapAsync } from 'ix/iterable/mapasync';
Expand All @@ -342,29 +373,32 @@ The IxJS project has a strict Code of Conduct that must be adhered at all times.
Read the [Contributing Guide](CONTRIBUTING.md) on how to get involved with the IxJS project. This includes our development process and how to test your code before committing.

### Packaging

`IxJS` is written in TypeScript, but the project is compiled to multiple JS versions and common module formats. The base IxJS package includes all the compilation targets for convenience, but if you're conscientious about your node_modules footprint, don't worry -- we got you. The targets are also published under the @reactivex namespace:

```sh
npm install @reactivex/ix-es5-cjs # ES5 CommonJS target
npm install @reactivex/ix-es5-esm # ES5 ESModules target
npm install @reactivex/ix-es5-umd # ES5 UMD target
npm install @reactivex/ix-es5-cls # ES5 Google Closure Compiler target
npm install @reactivex/ix-es2015-cjs # ES2015 CommonJS target
npm install @reactivex/ix-es2015-esm # ES2015 ESModules target
npm install @reactivex/ix-es2015-umd # ES2015 UMD target
npm install @reactivex/ix-es2015-cls # ES2015 Google Closure Compiler target
npm install @reactivex/ix-esnext-esm # ESNext CommonJS target
npm install @reactivex/ix-esnext-esm # ESNext ESModules target
npm install @reactivex/ix-esnext-umd # ESNext UMD target
npm install @reactivex/ix-esnext-cls # ESNext Google Closure Compiler target
npm install @reactivex/ix-ts # TypeScript target
npm install @reactivex/ix-es5-cjs # ES5 CommonJS target
npm install @reactivex/ix-es5-esm # ES5 ESModules target
npm install @reactivex/ix-es5-umd # ES5 UMD target
npm install @reactivex/ix-es5-cls # ES5 Google Closure Compiler target
npm install @reactivex/ix-es2015-cjs # ES2015 CommonJS target
npm install @reactivex/ix-es2015-esm # ES2015 ESModules target
npm install @reactivex/ix-es2015-umd # ES2015 UMD target
npm install @reactivex/ix-es2015-cls # ES2015 Google Closure Compiler target
npm install @reactivex/ix-esnext-esm # ESNext CommonJS target
npm install @reactivex/ix-esnext-esm # ESNext ESModules target
npm install @reactivex/ix-esnext-umd # ESNext UMD target
npm install @reactivex/ix-esnext-cls # ESNext Google Closure Compiler target
```

### Why do we package like this?
### Why we package like this

The JS community is a diverse group with a varied list of target environments and tool chains. Publishing multiple packages accommodates projects of all types. Friends targeting the latest JS runtimes can pull in the ESNext + ESM build. Friends needing wide browser support and small download size can use the UMD bundle, which has been run through Google's Closure Compiler with advanced optimizations.

If you think we missed a compilation target and it's a blocker for adoption, please open an issue. We're here for you ❤️.

## License ##
## License

The MIT License (MIT)

Expand Down

0 comments on commit 91c36a2

Please sign in to comment.