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('x-element', { prototype: proto }); var el = document.createElement('x-element'); // これで取れる console.log(el.shadowRoot.querySelector('.foo').textContent); //=> text
Shadow-Piercing descendant combinator is deprecated
最近Web Componentsのアップデート全然見てなかったけどCSSで外からShadow DOMをスタイリングするための/deep/
(>>>
)、::shadow
がdeprecatedになってた。
Shadow-Piercing descendant combinator, '/deep/' (aka '>>>') - Chrome Platform Status
gitでトラッキングされてないファイルも含めてstashする
なんとなく
$ git stash --all
ってやったら、ignoreされてるファイルも全部消えてファッってなった。
$ git stash -u # or $ git stash --include-untracked
が正しいっぽい。以下helpより。
If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state.
If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.
Polymer/platform.jsでdocument.currentScriptが動かない
Web ComponetsのPolyfillのPolymer/platform.jsでHTML import使ったときに、呼び出される側のHTMLのJSのdocumentを取得したいときに、
var doc = document.currentScript.ownerDocument;
ってやればとれるらしいんだけど、これがうまくPolyfillできなくて動かないらしい。
https://github.com/Polymer/HTMLImports/blob/a2accf9e3e15ee4584196a9aa5803cd5e7535820/src/HTMLImports.js#L196-L206
ので
var doc = document._currentScript.ownerDocument;
とする必要があるらしい。
Backbone.jsでPATCHをPUTに書き換える
Backbone.jsでsaveするときに patch: true にするとPATCHメソッドになってsaveに渡した引数だけをbodyに含める(patch :true しないとmodelの全attributesをbodyにしてPUTする)んだけど、API側がPATCHメソッドに対応してなかったりPATCHメソッドを通さないproxyがあったりした場合にPATCHをPUTに強制的に書き換えたい。
こうする。
var originalSync = Backbone.sync; Backbone.sync = function(method, model, options) { if (method === 'patch') options.type = 'PUT'; return originalSync(method, model, options); };
うーん。。
angular-scenarioで特定のテストだけ実行する
- describe -> ddescribe
- it -> iit
ってすればそのテストだけ実行される。今のところアンドキュメントな気がする。
describe('foo', function() { it('xxx', function() { ... }); iit('xxx', function() { ... }); // これだけ実行する it('xxx', function() { ... }); });