From fed0846a11f71850278e2e18d23bb026617c3faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Thu, 7 Jun 2018 14:48:47 +0200 Subject: [PATCH] [docs] #2174 docs and change log --- docs/change-log.md | 2 ++ docs/hyperscript.md | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/change-log.md b/docs/change-log.md index 682af63c..e77780f8 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -24,6 +24,8 @@ - API: `m.mount()` will only render its own root when called, it will not trigger a `redraw()` ([#1592](https://github.com/MithrilJS/mithril.js/pull/1592)) - API: Assigning to `vnode.state` (as in `vnode.state = ...`) is no longer supported. Instead, an error is thrown if `vnode.state` changes upon the invocation of a lifecycle hook. - API: `m.request` will no longer reject the Promise on server errors (eg. status >= 400) if the caller supplies an `extract` callback. This gives applications more control over handling server responses. +- hyperscript: when attributes have a `null` or `undefined` value, they are treated as if they were absent. [#1773](https://github.com/MithrilJS/mithril.js/issues/1773) ([#2174](https://github.com/MithrilJS/mithril.js/pull/2174)) +- hyperscript: when an attribute is defined on both the first and second argument (as a CSS selector and an `attrs` field, respectively), the latter takes precedence, except for `class` attributes that are still added together. [#2172](https://github.com/MithrilJS/mithril.js/issues/2172) ([#2174](https://github.com/MithrilJS/mithril.js/pull/2174)) #### News diff --git a/docs/hyperscript.md b/docs/hyperscript.md index 8ebe297b..26b0a27d 100644 --- a/docs/hyperscript.md +++ b/docs/hyperscript.md @@ -5,6 +5,7 @@ - [How it works](#how-it-works) - [Flexibility](#flexibility) - [CSS selectors](#css-selectors) +- [Attributes passed as the second argument](attributes-passed-as-the-second-argument) - [DOM attributes](#dom-attributes) - [Style attribute](#style-attribute) - [Events](#events) @@ -144,7 +145,23 @@ m("a.link[href=/]", { // Home ``` -If there are class names in both first and second arguments of `m()`, they are merged together as you would expect. +### Attributes passed as the second argument + +You can pass attributes, properties, events and lifecycle hooks in the second, optional argument (see the next sections for details). + +```JS +m("button", { + class: "my-button", + onclick: function() {/* ... */}, + oncreate: function() {/* ... */} +}) +``` + +If the value of such an attribute is `null` or `undefined`, it is treated as if the attribute was absent. + +If there are class names in both first and second arguments of `m()`, they are merged together as you would expect. If the value of the class in the second argument is `null`or `undefined`, it is ignored. + +If another attribute is present in both the first and the second argument, the second one takes precedence even if it is is `null` or `undefined`. ---