LearnNewsExamplesServices
Frontmatter
id7013
titleCreate `Neo.functional.defineComponent` Factory
stateClosed
labels
enhancement
assignees[]
createdAtJul 11, 2025, 4:07 AM
updatedAtJul 11, 2025, 11:25 AM
githubUrlhttps://github.com/neomjs/neo/issues/7013
authortobiu
commentsCount0
parentIssue6992
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 11, 2025, 11:25 AM

Create Neo.functional.defineComponent Factory

Closed v10.0.0-beta.6 enhancement
tobiu
tobiu commented on Jul 11, 2025, 4:07 AM

1. Summary

Implement a factory function that allows developers to define functional components using a plain JavaScript function, abstracting away the underlying class creation.

2. Rationale

This factory further simplifies the developer experience for "beginner mode" functional components, making the syntax more concise and familiar to developers accustomed to functional component patterns in other frameworks. It acts as the bridge between a pure function definition and the underlying Neo.functional.component.Base class.

3. Scope & Implementation Plan

  1. Create File: Create src/functional/defineComponent.mjs.
  2. Implement defineComponent: The factory will accept a configuration object (including className, optional ntype, and the createVdom function).
  3. Internal Class Generation: Internally, defineComponent will create a new class that extends Neo.functional.component.Base. It will apply the provided className and ntype to this new class.
  4. createVdom Method Assignment: The developer's createVdom function will be assigned as the createVdom method of the generated class's prototype.
  5. Integration with useConfig: Ensure that the context (this) within the developer's createVdom function (when executed by the generated component instance) allows useConfig to correctly associate state with that instance.

4. Example Usage

import { defineComponent } from 'neo/functional/defineComponent.mjs';
import { useConfig }       from 'neo/functional/useConfig.mjs';

const MyGreeting = defineComponent({
    className: 'MyApp.MyGreeting',
    createVdom: (config) => {
        const [name, setName] = useConfig('World');

        return {
            tag: 'div',
            text: `Hello, ${name}!`,
            listeners: {
                click: () => setName(name === 'World' ? 'Neo.mjs' : 'World')
            }
        };
    }
});

5. Definition of Done

  • Neo.functional.defineComponent factory is implemented and tested.
  • It successfully generates functional component classes from plain functions.
  • Generated components correctly utilize useConfig for state management.
tobiu added parent issue #6992 on Jul 11, 2025, 4:07 AM
tobiu added the enhancement label on Jul 11, 2025, 4:07 AM
tobiu referenced in commit 27d6ef8 - "Create Neo.functional.defineComponent Factory on Jul 11, 2025, 11:24 AM
tobiu closed this issue on Jul 11, 2025, 11:25 AM