Always expose stream on m.stream, use unpkg for docs (#1535)
... and document how streams are exposed in when loaded as <script> in global context
This commit is contained in:
parent
dc875fdbd3
commit
59ed3c7d48
2 changed files with 10 additions and 1 deletions
|
|
@ -40,6 +40,14 @@ Streams are NOT bundled with Mithril's core distribution. To include the Streams
|
|||
var Stream = require("mithril/stream")
|
||||
```
|
||||
|
||||
You can also download the module directly if your environment does not support a bundling toolchain:
|
||||
|
||||
```markup
|
||||
<script src="https://unpkg.com/mithril-stream"></script>
|
||||
```
|
||||
|
||||
When loaded directly with a `<script>` tag (rather that required), the stream library will be exposed as `window.m.stream`. If `window.m` is already defined (e.g. because you also use the main Mithril script), it will attach itself to the existing object. Otherwise it creates a new `window.m`. If you want to use streams in conjunction with Mithril as raw script tags, you should include Mithril in your page before `mithril-stream`, because `mithril` will otherwise overwrite the `window.m` object defined by `mithril-stream`. This is not a concern when the libraries are consumed as CommonJS modules (using `require(...)`).
|
||||
|
||||
---
|
||||
|
||||
### Signature
|
||||
|
|
|
|||
|
|
@ -113,4 +113,5 @@ createStream.combine = combine
|
|||
createStream.HALT = HALT
|
||||
|
||||
if (typeof module !== "undefined") module["exports"] = createStream
|
||||
else window.stream = createStream
|
||||
else if (typeof window.m === "function" && !("stream" in window.m)) window.m.stream = createStream
|
||||
else window.m = {stream : createStream}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue