Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Block<Token>

Type parameters

  • Token: any

Hierarchy

Implements

  • SelectorFactory

Index

Constructors

constructor

Properties

Protected _base

_base: Block | undefined

Private _blockReferences

_blockReferences: ObjectDictionary<Block>

Private _blockReferencesReverseLookup

_blockReferencesReverseLookup: Map<Block, string> = new Map()

Protected _children

_children: Map<string, BlockClass> = new Map()

Private _dependencies

_dependencies: Set<string>

array of paths that this block depends on and, if changed, would invalidate the compiled css of this block. This is usually only useful in pre-processed blocks.

Private _identifier

_identifier: FileIdentifier

Private _implements

_implements: Block[] = []

Protected _parent

_parent: never | null

Protected _root

_root: Block | Block

Protected _token

_token: Token

Private hasHadNameReset

hasHadNameReset: boolean = false

rootClass

rootClass: BlockClass

stylesheet

stylesheet: Root | undefined

Accessors

Protected ChildConstructor

base

  • get base(): Block | undefined
  • Get the style that this style inherits from, if any.

    This walks down the declared styles of the parent's inheritance chain, and attempts to find a matching directly declared style on each.

    The result is cached because it never changes and is decidable as soon as the style is instantiated.

    Returns Block | undefined

block

  • The block property is an alias for root. This isn't the dryest place to put this line, but every extension re-declared this interface itself and I wanted it in one place.

    Returns Block

    The base node in this tree.

classes

dependencies

  • get dependencies(): string[]

identifier

name

  • get name(): string

Protected parent

  • get parent(): never

Protected root

token

  • get token(): Token

Protected uid

  • get uid(): string

Methods

addBlockReference

  • addBlockReference(localName: string, other: Block): void

addClass

addDependency

  • addDependency(filepath: string): void
  • Add an absolute, normalized path as a compilation dependency. This is used to invalidate caches and trigger watchers when those files change.

    It is not necessary or helpful to add css-block files.

    Parameters

    • filepath: string

    Returns void

addImplementation

  • addImplementation(b: Block): number

all

  • all(shallow?: undefined | true | false): Styles[]
  • Return array self and all children.

    Parameters

    • Optional shallow: undefined | true | false

      Pass true to not include inherited objects.

    Returns Styles[]

    Array of Styles.

checkImplementation

  • Validate that this block implements all foreign selectors from blocks it implements.

    Parameters

    • b: Block

      The block to check implementation against.

    Returns Styles[]

    The Styles from b that are missing in the block.

checkImplementations

  • checkImplementations(): void

Protected children

Protected childrenHash

Protected childrenMap

debug

eachBlockReference

  • eachBlockReference(callback: function): void

Protected ensureChild

  • ensureChild(token: Child["token"], key?: undefined | string): BlockClass
  • Ensure a child node exists on this object at key. If it does not, create it. If key is not provided, use the child name as the key.

    Parameters

    • token: Child["token"]
    • Optional key: undefined | string

      string The key at which this child object should be (optional)

    Returns BlockClass

    The child node.

ensureClass

equal

  • equal(other: Block | undefined | null): undefined | null | true | false
  • Test if the supplied block is the same block object.

    Parameters

    • other: Block | undefined | null

      The other Block to test against.

    Returns undefined | null | true | false

    True or False if self and other are equal.

find

  • find(sourceName: string): Styles | undefined

getAncestors

  • getAncestors(): Array<Block>
  • Returns a new array of ancestors in order of inheritance with the first one being the immediate super block.

    If this block doesn't inherit, the array is empty.

    Returns Array<Block>

Protected getChild

  • getChild(token: Child["token"]): BlockClass | null

getClass

getImplementedBlocks

  • getImplementedBlocks(): Block[]

getParsedSelectors

  • getParsedSelectors(rule: Rule): ParsedSelector[]
  • Every Block tree maintains its own local cache of parsed selectors. From any sub-inheritable, or from the root inheritable itself, given a PostCSS Rule, ensure it is present in the root Block's parsed rule selectors cache, and return the ParsedSelector array.

    Parameters

    • rule: Rule

      PostCSS Rule

    Returns ParsedSelector[]

    ParsedSelector array

getReferencedBlock

  • getReferencedBlock(localName: string): Block | null

getReferencedBlockLocalName

  • getReferencedBlockLocalName(block: Block | undefined): string | null

isAncestorOf

  • isAncestorOf(other: Block | undefined | null): boolean

lookup

merged

  • merged(): MultiMap<string, Styles>

Protected newChild

nodeAsStyle

  • nodeAsStyle(node: selectorParser.Node): [Styles, number] | null

Protected resolveChild

  • resolveChild(token: Child["token"]): BlockClass | null

Protected resolveChildren

Protected resolveChildrenHash

  • resolveChildrenHash(): ObjectDictionary<BlockClass>

Protected resolveChildrenMap

resolveClass

resolveInheritance

  • resolveInheritance(): Block[]
  • Compute all block objects that are implied by this block object through inheritance. Does not include this object or the styles it implies through other relationships to this object.

    The values are returned in inheritance order, with the first value returned (if any) having no base, and the the last value returned (if any) being the base of this object.

    If nothing is inherited, this returns an empty array.

    Returns Block[]

    The array of nodes this node inherits from.

rewriteSelector

rewriteSelectorNodes

  • rewriteSelectorNodes(nodes: selectorParser.Node[], config: ResolvedConfiguration): selectorParser.Node[]

rewriteSelectorToString

setBase

  • setBase(base: Block): void

Protected setChild

setName

  • setName(name: string): void
  • Sets name value of this Block. Block names may change depending on the value passed to its block-name property in :scope.

    prop

    name string The new uid for this Block.

    Parameters

    • name: string

    Returns void

toJSON

  • toJSON(): string
  • Objects that contain Blocks are often passed into assorted libraries' options hashes. Some libraries like to JSON.stringify() their options to create unique identifiers for re-run caching. (ex: Webpack, awesome-typescript-loader) Blocks contain circular dependencies, so we need to override their toJSON method so these libraries don't implode.

    Returns string

    The name of the block.

Protected tokenToUid

  • tokenToUid(token: Token): string
  • The tokenToUid method would ideally be a static method, but Typescript doesn't expose class generics to static methods, so it needs to be a protected method. In order to map children to generic Tokens, we need a way to map any given Token shape to a UID. By default, we stringify the token passed to us. If more complex behavior is required, this method can be overridden.

    Parameters

    • token: Token

    Returns string

    A unique string that represents this token.

transitiveBlockDependencies

  • transitiveBlockDependencies(): Set<Block>

Generated using TypeDoc