Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block的before after不明白 #69

Open
HerringtonDarkholme opened this issue Jun 2, 2016 · 1 comment
Open

block的before after不明白 #69

HerringtonDarkholme opened this issue Jun 2, 2016 · 1 comment
Labels

Comments

@HerringtonDarkholme
Copy link
Contributor

screen shot 2016-06-02 at 13 46 32

screen shot 2016-06-02 at 13 46 59

@hax
Copy link
Contributor

hax commented Jun 2, 2016

c.jedi定义了一个fragment #main

b.jedi导入了c.jedi并追加了#main::before#new-blockb.jedi的实际结果相当于是:

div
  'hahah'
  #main
    #main::before
      'hoho'

#new-block 被丢弃了,因为在c.jedi里并没有对应的#new-block。如果你希望提供#new-block给其他模板去填充,应该把#new-block缩进在#main::before里。这样就相当于:

div
  'hahah'
  #main
    #main::before
      'hoho'
      #new-block
         'new-block'

这样a.jedi导入b.jedi的结果就相当于

div
  'hahah'
  #main
    'from a'

整个#main被替换了。#new-block::after(注意语法是::after不是append)也被丢弃了,因为#main被替换了,里面并没有#new-block

假如a.jedi里的#main换成#main::after则结果相当于:

div
  'hahah'
  #main
    #main::before
      'hoho'
      #new-block
         'new-block'
         #new-block::after
           'hahahha'
    #main::after
       'from a'

BTW,jedi的fragment机制和shadow dom的slot机制的语义是完全一致的。(语法上略有区别,另外jedi有::before::after。)

注意,jedi的::before::after与jade的prependappend的区别是:jade的每一级继承都可以不断prepend和append,但jedi中是固定替换,和css的伪元素语义一样,或者说类似OO的override,一共只有3个方法可以override:

class Fragment {
   constructor(name) {}
   render() {
      this.before()
      this.content()
      this.after()
   }
   before() {}
   after() {}
   private content() {}
}
:import ...
  #main 
     ...

相当于override render()方法。

@hax hax added the question label Jun 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants