Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable serialization of enumerable and actions #79

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

GeekyEggo
Copy link
Member

@GeekyEggo GeekyEggo commented Jan 3, 2025

Changes

  • Update Enumerable to include a toJSON and toString implementation, allowing enumerables to be serialized.
  • Update ActionContext, KeyAction, and DialAction to include getters when serializing.

Motive

When logging the streamDeck.actions, or this.actions within an action, nothing is logged. With Enumerable yielding results lazily, JavaScript does not evaluate the collection when formatting the logs as part of the JSON.stringify call. To resolve this, we can implement toJSON and toString functions on Enumerable.

With the aforementioned functions implemented, we now have actions logging, however the result looks something like this:

// streamDeck.logger.info(streamDeck.actions);
2025-01-03T18:54:11.131Z INFO  [{}]

This is caused by the KeyAction, DialAction, and ActionContext classes relying on getters for immutability. With toJSON implemented on these classes, we finally see a meaningful log entry:

// streamDeck.logger.info(streamDeck.actions);
2025-01-03T18:54:11.131Z INFO  [{"controllerType":"Keypad","device":{"id":"2d18b00bc2a0e9fd2073f1d2a1a0a2ed"},"id":"b2a6bb43802a330a41e3ab74e8a12e95","manifestId":"com.richard.test.action","coordinates":{"column":3,"row":1},"isInMultiAction":false}]

@GeekyEggo GeekyEggo changed the title feat: enable serialization of enumerable feat: enable serialization of enumerable, and actions Jan 3, 2025
@GeekyEggo GeekyEggo changed the title feat: enable serialization of enumerable, and actions feat: enable serialization of enumerable and actions Jan 3, 2025
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.

2 participants