-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Is your refactoring request related to a problem? Please describe.
Refactor the tedge flows interface and data types.
Describe the solution you'd like
The following items should be refactored to improve the overall tedge flows concept:
Item 1: Remove onConfigUpdate function
Remove the onConfigUpdate() function from the flow concept. Whilst the underlying functionality is useful, it is not a common case yet, and we might be able to solve it in a different way in the future. Removing this interface reducing the size of the public API for the initial launch of the feature.
Item 2: Replace Timestamp type with the JavaScript Date object - Done
Replace the Timestamp type with the JavaScript native Date object.
The type should be replaced in the following areas:
- In the onInterval function, the first argument
- In the
message.timestamp, and rename the property tomessage.time
Below shows an example of the function signatures with the change in the timestamp data type.
export function onMessage(message: Message, config: any) {
console.log(`Message received at: ${message.time}`);
return [];
}
export function onInterval(time: Date, config: any) {
return [];
}Item 3: Replace config with context in functions
Change the function signatures of onMessage and onInterval to rename the config argument to context, however context is an object which should include a config property (which contains the step's configuration). Below shows an example of the context object and its relationship to the "config" property.
Example Context object
{
config: {
foo: "bar"
}
}Below shows an example of the renamed function signatures which use the new "context" type.
export function onMessage(message: Message, context: any) {
console.log(`Message has context: ${context.config}`);
return [];
}
export function onInterval(time: Date, context: any) {
return [];
}Item 4: Rename payload_raw to payload in the message data object
In the message type, rename payload_raw to payload (overwriting the previous string type used in payload). This will prevent duplicating the data being passed to the flows. JavaScript helper functions can be provided in the meantime to make it easier to encode and decode payloads to and from the JavaScript Uint8Array type.
export interface Message {
time?: Date; // Previously a custom Timestamp object, but now a JavaScript Date
topic: string;
payload?: Uint8Array; // Previously was a string, and was duplicated in payload_raw
retain: boolean;
}Describe alternatives you've considered
Additional context