Skip to content

Add an OOP-based way of adding features#100

Open
cornusandu wants to merge 8 commits into
NotValra:mainfrom
cornusandu:better-feat-def-1
Open

Add an OOP-based way of adding features#100
cornusandu wants to merge 8 commits into
NotValra:mainfrom
cornusandu:better-feat-def-1

Conversation

@cornusandu

@cornusandu cornusandu commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Overview

Add a way of defining features via class decorators.

How to?

Make a class

For your feature, make a class that has:

  • A constructor that initialises state
  • init(page) / async init(page): initialise feature
  • onDOMLoaded(): runs on 'DOMContentLoaded'
  • onPageLoaded(): runs on 'load'

Using the decorator

Use the decorator like this (importing it from core/defineFeature/defFeat.ts:

@feature({ paths: ["*"] })  // you can also just do @feature(), and it'll always get loaded
class MyFeature {
...
}

Load your feature

Add the following line to core/defineFeature/featList.ts:

export { YourClassNameHere } from "yourFeaturesPathHere";

Note

Please keep in mind that decorators will NOT be in the build output. They will get resolved to JavaScript code that Chrome supports entirely at build-time. Eslint was also configured to understand the syntax.

@cornusandu cornusandu marked this pull request as draft June 14, 2026 18:41
Fixed erroring out if the document was already loaded / interactive and the feature class didn't have onDOMLoaded() or onPageLoaded()
@cornusandu cornusandu marked this pull request as ready for review June 15, 2026 12:29
* Passed path to constructor

* Improved types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant