2016-03-01から1ヶ月間の記事一覧

FactoryGirlでActiveRecord以外のデータをつくる

例えばHashie::Mashを返したい場合はこんな感じ。 FactoryGirl.define do factory :post, class: Hashie::Mash do title "foo" body "bar" end end FactoryGirl.build(:post).class #=> Hashie::Mash FactoryGirl.build(:post) #=> {"title"=>"foo", "body"=…

ES6でN個の配列

Array.prototype.keysはIteratorを返すのでArray.fromに食わせる Array.from(Array(5).keys()); //=> [0, 1, 2, 3, 4] もしくは Array.from({ length: 5 }).map((v, k) => k); //=> [0, 1, 2, 3, 4] Array.fromの第二引数はmap的な役割があるので Array.from…

ShadowDOMの外から内部の要素を取得する

shadowRootでshadowRootが取れるのでそこから辿れる。 var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { var shadowRoot = this.createShadowRoot(); shadowRoot.innerHTML = '<span class="foo">text</span>'; }; document.registerElement(…

Shadow-Piercing descendant combinator is deprecated

最近Web Componentsのアップデート全然見てなかったけどCSSで外からShadow DOMをスタイリングするための/deep/(>>>)、::shadowがdeprecatedになってた。 Shadow-Piercing descendant combinator, '/deep/' (aka '>>>') - Chrome Platform Status