uu.hash, uu.attr, uu.css, uu.css3 を修正

uupaa.js 0.7 の修正履歴です。興味がない方は読み飛ばしてください。

uu.hash と uu.attr の I/F を修正しました

  • uu.hash でカンマ(,)とスペース以外のスプリッターを利用可能にしました
    • デフォルトのスプリッターは(,) です。
    • 第二引数にスプリッターを指定した場合は、第三引数に value の型(uu.STR または uu.NUM) も指定する必要があります。
      • uu.NUM を指定すると、 uu.hash.num と同じ機能になります。
      • 現在は、uu.STR と uu.NUM だけですが、将来 uu.DATE や uu.RGBA などもサポートするかもしれません。
  • uu.hash の修正にあわせ、uu.ary 側も修正を行いました
    • uu.ary.clone() を追加しました。
uu.js [修正前]
  // [1][through] uu.hash({ key: "val" }) -> { key: "val" }
  // [2][to hash] uu.hash("key", mix) -> { key: mix }
  // [3][to hash(split comma)] uu.hash("key,a,key2,b") -> {key: "a", key2: "b"}
  // [4][to hash(split space)] uu.hash(" key a key2 b") -> {key: "a", key2: "b"}
  hash:   uumix(uuhash, {

uu.js [修正後]
  // [1][through]      uu.hash({ key: "val" }) -> { key: "val" }
  // [2][pair to hash] uu.hash("key", mix)     -> { key: mix }
  // [3][split(,)]     uu.hash("key,a,key2,b")              -> { key:"a",key2:"b" }
  // [4][split(;)]     uu.hash("key;a;key2;b", ";", uu.STR) -> { key:"a",key2:"b" }
  // [5][split(,) num] uu.hash("key,0,key2,1", ",", uu.NUM) -> { key:0,  key2:1   }
  hash:   uumix(uuhash, {

uu.js [修正前]
  // [1][clone]             uu.ary(Array) -> new Array
  // [2][convert NodeList]  uu.ary(NodeList) -> [elm, ...]
  // [3][convert arguments] uu.ary(arguments) -> [elm, ...]
  // [4][split comma]       uu.ary("word,word") -> ["word", "word"]
  // [5][split space]       uu.ary(" word word") -> ["word", "word"]
  ary:    uumix(uuary, {

uu.js [修正後]
  // [1][through]           uu.ary([1, 2])     -> [1, 2]
  // [2][literal to ary]    uu.ary(12)         -> [12]
  // [3][string to ary]     uu.ary("12")       -> ["12"]
  // [4][string to ary(no split)]
  //                        uu.ary("12,12", 0) -> ["12,12"]
  // [5][convert NodeList]  uu.ary(NodeList)   -> [elm, ...]
  // [6][convert arguments] uu.ary(arguments)  -> [elm, ...]
  // [7][string split(,)]   uu.ary("word,word") -> ["word", "word"]
  // [8][string split(;)]   uu.ary("word;word", ";") -> ["word", "word"]
  ary:    uumix(uuary, {
    clone:      uuaryclone,     // uu.ary.clone([1, 2]) -> new Array(1, 2)
  }

uu.attr, uu.css, uu.css3 の利便性の向上と整合性について修正を行いました。

  • uu.attr.get[1] と [2] の機能を、uu.attr に移動しました
  • uu.attr.set[1] を追加しました。
uu.js [修正前]
  // [1][get one attr]   uu.attr(node, "attr") -> "value"
  // [2][get some attrs] uu.attr(node, "attr1,attr2") -> { attr1: "val", attr2: "val" }
  // [3][set one attr]   uu.attr(node, "attr", "val") -> node
  // [4][set some attrs] uu.attr(node, { attr: "val" }) -> node
  attr:   uumix(uuattr, {
    get:        uuattrget,      // [1][get all attrs]  uu.attr.get(node) -> { all: attrs }
                                // [2][get many attrs] uu.attr.get(node, 1) -> { many: attrs }
                                // [3][get one attr]   uu.attr.get(node, "attr") -> String
                                // [4][get some attrs] uu.attr.get(node, "attr,...") -> Hash
    set:        uuattrset       // [1][set some attrs] uu.attr.set(node, { id: "hoge" }) -> node
  }),

uu.js [修正後]
  // [1][get all  attrs] uu.attr(node) -> { all: attrs }
  // [2][get many attrs] uu.attr(node, 1) -> { many: attrs }
  // [3][get one  attr]  uu.attr(node, "attr") -> "value"
  // [4][get some attrs] uu.attr(node, "attr1,attr2") -> { attr1: "val", attr2: "val" }
  // [5][set one  attr]  uu.attr(node, "attr", "val") -> node
  // [6][set some attrs] uu.attr(node, { attr: "val" }) -> node
  attr:   uumix(uuattr, {
    get:        uuattrget,      // [1][get one  attr]  uu.attr.get(node, "attr") -> String
                                // [2][get some attrs] uu.attr.get(node, "attr,...") -> Hash
    set:        uuattrset       // [1][set one  attr]  uu.attr.set(node, key, val ) -> node
                                // [2][set some attrs] uu.attr.set(node, { key: val, ... }) -> node
  }),
  • uu.css.set[1] を追加しました。
uu.css.js [修正前]
  set:          uucssset,       // [1] uu.css.set(node, { color: "red" }) -> node

uu.css.js [修正後]
  set:          uucssset,       // [1][set one  style]  uu.css.set(node, "color", "red") -> node
                                // [2][set some styles] uu.css.set(node, { color: "red" }) -> node
  • uu.css3.get と uu.css3.set の I/F を uu.css に合わせました
  • uu.css3.set の 第四引数(redraw) を削除しました
uu.css3.js [修正前]
uu.css3 = uu.mix(uucss3, {
  get:          uucss3get,      // uu.css3.get(node, prop) -> "extend / computed-like style"
  set:          uucss3set,      // uu.css3.set(node, prop, value, redraw = 0) -> node

uu.css3.js [修正後]
uu.css3 = uu.mix(uucss3, {
  get:          uucss3get,      // [1][get one  style]  uu.css3.get(node, "color") -> "red"
                                // [2][get some styles] uu.css3.get(node, "color,text-align") -> {color:"red", textAlign:"left"}
  set:          uucss3set,      // [1][set one  style]  uu.css3.set(node, "-uu-box-shadow", "3px 3px 3px") -> node
                                // [2][set some styles] uu.css3.set(node, { "-uu-box-shadow": "3px 3px 3px" }) -> node

今回の変更に伴い、以下の書き換えが必要になります。

  • uu.hash(" word word") ⇒ uu.hash("word word", " ", uu.STR)
  • uu.ary(" word word") ⇒ uu.ary("word word", " ")
  • uu.ary([1, 2]) ⇒ uu.ary.clone([1, 2]) または [1.2].slice()
  • uu.css3.set(node, "prop", "value", 1) ⇒ uu.css3.set(node, "prop", "value") + uu.css3.redraw()

今回の修正でこのような記述が可能になりました。

修正前
function hoge(mix) { // @param String/Number/Array/FakeArray:
  var ary = uu.isary(mix) ? mix
          : uu.type(mix, uu.FAKE) ? uu.ary(mix)
          : [mix];

}

修正後
function hoge(mix) { // @param String/Number/Array/FakeArray:
  var ary = uu.ary(mix);

}


この変更は次回のリリースから適用されます。