Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

contributing.md 11 KiB

vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Contributing to RxJS #
  2. Want to contribute to the Reactive Extensions for JavaScript (RxJS)? There are many ways of helping whether contributing code, documentation, examples, podcasts, videos and presentations.
  3. # Get Involved!
  4. In [the issue tracker](https://github.com/Reactive-Extensions/RxJS/issues), bugs can only be assigned to people who have commit access. Also, we aspire to make as many bugs as possible "owned" by assigning them to a core Rx contributor. Therefore, just because a bug is assigned doesn't mean it's being actively worked on. We (the core contributors) are all busy, and welcome help from the community. If you see a bug you'd like to work on that's assigned but appears to be dormant, communicate with the bug's owner with an @-reply in a comment on the issue page. If you see a bug you'd like to work on that's unassigned, it's fair game: comment to say you'd like to work on it so that we know it's getting attention.
  5. # Pull Requests
  6. To make a pull request, you will need a GitHub account; if you're unclear on this process, see GitHub's documentation on [forking](https://help.github.com/articles/fork-a-repo/) and [pull requests](https://help.github.com/articles/using-pull-requests). Pull requests should be targeted at RxJS's master branch. Before pushing to your Github repo and issuing the pull request, please do two things:
  7. 1. Rebase your local changes against the master branch. Resolve any conflicts that arise.
  8. 2. Run the full RxJS test suite by running `grunt` in the root of the repository.
  9. Pull requests will be treated as "review requests", and we will give feedback we expect to see corrected on style and substance before pulling. Changes contributed via pull request should focus on a single issue at a time, like any other. We will not look kindly on pull-requests that try to "sneak" unrelated changes in. Note for bug fixes, regression tests should be included, denoted by Issue Number so that we have full traceability.
  10. # What Are We Looking For?
  11. For documentation, we are looking for the following:
  12. - API Documentation that is missing or out of date
  13. - "How Do I?" examples
  14. - Comparison to other libraries
  15. - Comparison to Promises
  16. - Introduction material
  17. - Tutorials
  18. For coding, we have strict standards that must be adhere to when working on RxJS. In order for us to accept pull requests, they must abide by the following:
  19. - [Coding Standard](#coding-standard)
  20. - [Tests](#tests)
  21. - [Documentation](#documentation)
  22. ## Coding Standard
  23. For RxJS, we follow the [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml) and adhere to it strictly in areas such as documentation using JSDoc. The only exception to extending native prototypes is to polyfill behavior which may not exist in all browsers yet, for example, many of the [Array#extras](http://blogs.msdn.com/b/ie/archive/2010/12/13/ecmascript-5-part-2-array-extras.aspx) are implemented in compatibility builds. We also strictly follow [our design guidelines](https://github.com/Reactive-Extensions/RxJS/tree/master/doc/designguidelines) as well.
  24. ### Supporting Multiple Platforms
  25. RxJS runs on a number of platforms and supports many styles of programming. RxJS supports [Universal Module Definition (UMD)](https://github.com/umdjs/umd) which allows the library to work in a number of environments such as [Asynchronous Module Definition (AMD)](https://github.com/amdjs/amdjs-api/wiki/AMD), [CommonJS](http://wiki.commonjs.org/wiki/CommonJS), [Node.js](http://nodejs.org), [RingoJS](http://ringojs.org/), [Narwhal](https://github.com/280north/narwhal), the browser and other environments such as [Windows Script Host (WSH)](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) and embedded devices such as [Tessel](http://tessel.io).
  26. RxJS is committed to using the latest JavaScript standards as they start to arrive, for example, supporting generators, Maps, Sets, and Observable versions of new Array methods. We also are committed to supporting legacy code as well through compatibility builds, even supporting browsers back to IE6, Firefox 3, and older versions of Node.js. Should behavior not exist in those platforms, that behavior must be polyfilled, and made available in `*.compat.js` files only. For example, we have `rx.lite.js` which supports modern browsers greater than or equal to IE9, and `rx.lite.compat.js` for older browsers before IE9 and modern Firefox builds. In special cases such as event handling is different, we must provide a mainstream version of the file as well as a compat file, the latter which is included in the compat file.
  27. ### Implementing Custom Operators
  28. We welcome custom operators to RxJS if they make sense in the core RxJS, as opposed to belonging in user land. There are a number of rules that must be adhered to when implementing a custom operator including:
  29. - Prefer composition over implementing a totally new operator from scratch
  30. - If the operator introduces any notion of concurrency, then a scheduler must introduced. Usage of concurrency primitives such as `setTimeout`, `setInterval`, etc are forbidden. This is to ensure easy testability.
  31. - The scheduler must be optional with the appropriate default picked
  32. - `Rx.Scheduler.immediate` for any immediate blocking operations
  33. - `Rx.Scheduler.currentThread` for any immediate blocking operators that require re-entrant behavior such as recursive scheduling.
  34. - `Rx.Scheduler.timeout` for any operator that has a notion of time
  35. To make this concrete, let's implement a custom operator such as an implementation of `_.reject` from [Underscore.js](http://underscorejs.org/) / [Lo-Dash](http://lodash.com/).
  36. ```js
  37. /**
  38. * The opposite of _.filter this method returns the elements of a collection that the callback does **not** return truthy for.
  39. * @param {Function} [callback] The function called per iteration.
  40. * @param {Any} [thisArg] The this binding of callback.
  41. * @returns {Observable} An Observable sequence which contains items that the callback does not return truthy for.
  42. */
  43. Rx.Observable.prototype.reject = function (callback, thisArg) {
  44. callback || (callback = Rx.helpers.identity);
  45. var source = this;
  46. return new Rx.AnonymousObservable(function (observer) {
  47. var i = 0;
  48. return source.subscribe(
  49. function (x) {
  50. var noYield = true;
  51. try {
  52. noYield = callback.call(thisArg, x, i++, source);
  53. } catch (e) {
  54. observer.onError(e);
  55. return;
  56. }
  57. if (!noYield) { observer.onNext(x); }
  58. },
  59. observer.onError.bind(observer),
  60. observer.onCompleted.bind(observer)
  61. );
  62. });
  63. };
  64. ```
  65. Of course, we could have implemented this using composition as well, such as using `Rx.Observable.prototype.filter`.
  66. ```js
  67. /**
  68. * The opposite of _.filter this method returns the elements of a collection that the callback does **not** return truthy for.
  69. * @param {Function} [callback] The function called per iteration.
  70. * @param {Any} [thisArg] The this binding of callback.
  71. * @returns {Observable} An Observable sequence which contains items that the callback does not return truthy for.
  72. */
  73. Rx.Observable.prototype.reject = function (callback, thisArg) {
  74. callback || (callback = Rx.helpers.identity);
  75. return this.filter(function (x, i, o) { return !callback.call(thisArg, x, i o); });
  76. };
  77. ```
  78. To show an operator that introduces a level of concurrency, let's implement a custom operator such as an implementation of `_.pairs` from [Underscore.js](http://underscorejs.org/) / [Lo-Dash](http://lodash.com/). Note that since this requires recursion to implement properly, we'll use the `Rx.Scheduler.currentThread` scheduler.
  79. ```js
  80. var keysFunction = Object.keys || someKeysPolyfill;
  81. /**
  82. * Creates an Observable with an of an object’s key-value pairs.
  83. * @param {Object} obj The object to inspect.
  84. * @returns {Observable} An Observable with an of an object’s key-value pairs.
  85. */
  86. Rx.Observable.pairs = function (obj, scheduler) {
  87. scheduler || (scheduler = Rx.Scheduler.currentThread);
  88. return new Rx.AnonymousObservable(function (observer) {
  89. var keys = keysFunction(object),
  90. i = 0,
  91. len = keys.length;
  92. return scheduler.scheduleRecursive(function (self) {
  93. if (i < len) {
  94. var key = keys[i++], value = obj[key];
  95. observer.onNext([key, value]);
  96. self();
  97. } else {
  98. observer.onCompleted();
  99. }
  100. });
  101. });
  102. };
  103. ```
  104. Note that all operators must have the documentation and must be split out into its own file. This allows us to be able to put it in different files, or make it available in custom builds.
  105. ## Tests
  106. When a new operator is written for RxJS, in order to accepted, must be accompanied by tests. RxJS currently uses [QUnit](http://qunitjs.com/) as a straight forward way to test our code. These tests are automatically executed by our [Grunt](http://gruntjs.com/) setup to concatenate files, minimize, create source maps, and finally run all the tests in the [tests folder](https://github.com/Reactive-Extensions/RxJS/tree/master/tests). Each file that we produce, for example, `rx.js` has an accompanying test file such as `rx.html`, which includes tests for all operators included in that file.
  107. Each operator under test must be in its own file to cover the following cases:
  108. - Never
  109. - Empty
  110. - Single/Multiple Values
  111. - Error in the sequence
  112. - Never ending sequences
  113. - Early disposal in sequences
  114. If the operator has a callback, then it must cover the following cases:
  115. - Success with all values in the callback
  116. - Success with the context, if any allowed in the operator signature
  117. - If an error is thrown
  118. To get a good feeling on what kind of rigor is required for testing, check out the following examples:
  119. - [`concatMap`](https://github.com/Reactive-Extensions/RxJS/blob/master/tests/observable/concatmap.js)
  120. - [`from`](https://github.com/Reactive-Extensions/RxJS/blob/master/tests/observable/from.js)
  121. ## Documentation
  122. Documentation is also a must, as all external operators and types must be documented and put in the [API Folder](https://github.com/Reactive-Extensions/RxJS/tree/master/doc/api). Each operator on an Observable must have its own file in the [Operators Folder](https://github.com/Reactive-Extensions/RxJS/tree/master/doc/api/core/operators).
  123. For operators, they must be linked from the [`Observable`](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md) API document. In addition, each operator must be listed in which file it belongs in the [Libraries Folder](https://github.com/Reactive-Extensions/RxJS/tree/master/doc/libraries).
  124. The standard format of operators must be such as the [`of`](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/of.md) operator which includes:
  125. - File Location
  126. - Method signature
  127. - Method description
  128. - List of Arguments
  129. - Return type (if there is one)
  130. - An example
  131. - File Distribution(s)
  132. - NuGet Distribution
  133. - NPM Distribution
  134. - Unit Tests