Skip to content

Programmatically Construct ViewTemplates with Bindings #6080

Answered by EisenbergEffect
KingOfTac asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a function that will create a template for a single element, with an arbitrary list of attributes that can be strings, bindings, directives, etc.

Note: This is using fast-element 2.0. It should be very similar with the current version.

export function createSingleElementView<
    TSource = any,
    TParent = any,
    TContext extends ExecutionContext<TParent> = ExecutionContext<TParent> // I think just ExecutionContext in current
>(tagName: string, attributes: Record<string, string | TemplateValue<TSource, TParent, TContext>> = {}) {
    const markup = [`<${tagName}`];
    const values: TemplateValue<TSource, TParent, TContext>[] = [];

    for (const key in attributes) {
        m…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@KingOfTac
Comment options

KingOfTac Jun 9, 2022
Collaborator Author

@EisenbergEffect
Comment options

Comment options

You must be logged in to vote
6 replies
@KingOfTac
Comment options

KingOfTac Jun 9, 2022
Collaborator Author

@KingOfTac
Comment options

KingOfTac Jun 9, 2022
Collaborator Author

@EisenbergEffect
Comment options

@KingOfTac
Comment options

KingOfTac Jun 17, 2022
Collaborator Author

@EisenbergEffect
Comment options

Answer selected by EisenbergEffect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area:fast-element Pertains to fast-element
2 participants