Harmonize the exposing process
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 45
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Currently, the exposing process is composed of two phases: produce and expose. The two phases are handled by the produce function and the expose method of the ExposedThing interface. The problem that my colleagues and I saw is in the mixed nature of the ExposedThing interface.
First of all, semantically, it sounds strange that a produce method creates an ExposedThing object that is actually not exposed yet until one calls the expose method on it. Secondly, technically, in an ExposedThing the handlers can be changed after the exposition, causing possible problems and side effects if the object is passed in different parts of the program. (what if one library function adds its own handler, or it expects a no-exposed thing).
Discussion
Define a strong split between the two phases and let be ExposedThing an immutable object. In concrete something like the following (typescript notation):
function produce(init: ExposedThingInit): Promise<ProducedThing>;
export interface ProducedThing {
setPropertyReadHandler(name: string, handler: PropertyReadHandler): ProducedThing;
setPropertyWriteHandler(name: string, handler: PropertyWriteHandler): ProducedThing;
setPropertyObserveHandler(name: string, handler: PropertyReadHandler): ProducedThing;
setPropertyUnobserveHandler(name: string, handler: PropertyReadHandler): ProducedThing;
setActionHandler(name: string, handler: ActionHandler): ProducedThing;
setEventSubscribeHandler(name: string, handler: EventSubscriptionHandler): ProducedThing;
setEventUnsubscribeHandler(name: string, handler: EventSubscriptionHandler): ProducedThing;
setEventHandler(name: string, handler: EventListenerHandler): ProducedThing;
getPartialThingDescription(): Partial<ThingDescription>;
async expose(): Promise<ExposedThing>
}
export interface ExposedThing {
destroy(): Promise<void>;
getThingDescription(): ThingDescription;
emitEvent(name: string, data: InteractionInput): void;
emitPropertyChange(name: string): void;
}
This way we can detect silly errors like emitEvent before exposing or setting a handler in an exposed thing at compile time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the produce function and ExposedThing interface described in the issue, then trace how handlers and exposure currently work. Compare those entry points with the proposed ProducedThing and immutable ExposedThing split; done means the lifecycle and handler restrictions are represented consistently in the TypeScript API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100