SSE | Sygnal Site Engine
Community ForumSupport Us!Micro-Consulting
  • Sygnal Site Engine ( SSE )
  • The SSE Architecture
  • What's New
  • Feature Roadmap
    • Component Architecture
    • File Copy & Augmented Builds
    • SA5 Integration
  • Installation & Setup
    • Setup Github Repository
    • Setup Netlify
      • jsDelivr
    • Setup Webflow
    • Advanced Install Notes
      • Creating a Persistent Test Env
      • Add SSE to an Existing Repo
  • Usage Notes
    • Developing with SSE
    • Building & Deploying Code
    • Code Structure
    • Page Router
    • Components
      • Components Future Notes
    • Source Structure & Key Files
      • Utilities
      • Route Dispatcher
      • Infrastructure
      • Usage Notes
    • SCSS
    • Useful Library Additions
      • Adding Libraries
      • Luxon
      • Cookies
      • Core Libraries
      • Extending Capabilities
    • Best Practices
    • Unit Testing
      • Using Google Sheets as a Unit Test Data Source
      • Datetime & Timezone Tests
      • Best Practices
      • Page 1
  • Sygnal Devproxy
    • What is Devproxy?
    • Devproxy Setup
    • Cloudflare Setup
    • Webflow Site Configuration
    • Configurations
      • Controlling deployment flow
    • Future
  • Tech Stack
    • Source Code Repository
    • Visual Studio Code
    • Developer IDE
    • Dev Hosting
    • Code CDN
    • Devproxy
  • Further Development
    • Dev Team Notes
      • Engine Mode
    • Reference Project
    • Future
      • Component Development
      • Reactive State Management
      • Expand Script Loading
    • Devmode
    • CI/CD Discussions
      • Page 2
    • SA5
  • Tools
    • Webflow Designer Notation
  • SPECIAL ENHANCEMENTS
    • cookie.js
    • PostHog
Powered by GitBook
On this page
  • Naming & Routing
  • Concept code
  1. Usage Notes
  2. Components

Components Future Notes

Naming & Routing

We are considering the possibility of a dual-routing architecture.

The component class itself might have a component name built into it using a TypeScript decorator, like so

Concept code

function Component(name: string) {
    return function (constructor: Function) {
        Reflect.defineMetadata('componentName', name, constructor);
    }
}
@Component('my-component')
class MyComponent {
    constructor() {
        console.log('MyComponent initialized');
    }
}

@Component('another-component')
class AnotherComponent {
    constructor() {
        console.log('AnotherComponent initialized');
    }
}
import 'reflect-metadata';

function createComponentFromAttribute(attrValue: string): any {
    const components = [MyComponent, AnotherComponent];

    for (const component of components) {
        const name = Reflect.getMetadata('componentName', component);
        if (name === attrValue) {
            return new component();
        }
    }

    throw new Error(`Component with name "${attrValue}" not found.`);
}

// Usage
const component = createComponentFromAttribute('my-component'); // Instantiates `MyComponent`
function initializeComponents() {
    const elements = document.querySelectorAll('[data-component]');
    elements.forEach(elem => {
        const componentName = elem.getAttribute('data-component');
        if (componentName) {
            const componentInstance = createComponentFromAttribute(componentName);
            if (componentInstance) {
                console.log(`${componentName} component initialized`, componentInstance);
            }
        }
    });
}

PreviousComponentsNextSource Structure & Key Files

Last updated 8 months ago