Skip to content

Formatter should be static #195

Closed

Description

@grant

I noticed the formatter lives within the CloudEvent object.

CloudEvent {
  spec:
   Spec1 {
     payload:
      { specversion: '1.0',
        id: '1234',
        time: '2020-05-28T20:46:18.970Z',
        source: '/some/source',
        type: 'example',
        datacontenttype: undefined,
        data: undefined,
        subject: undefined } },
  formatter: JSONFormatter {},
  extensions: [] }

This doesn't really make sense since we can have 1000 CloudEvent objects with the same formatter.

Maybe it should be a static class/set of methods.

Activity

  1. lance commented on May 29, 2020

    @lance
    Member

    I was thinking actually of removing it entirely from the class, along with the format() function. Instead, expose a top level Formatter class or formatter() function that takes a CloudEvent and formats it as JSON by default. But of course that would be a breaking change and require a version bump. Making it static is a good first step.

  2. lholmquist commented on Jun 10, 2020

    @lholmquist
    Contributor

    Somewhat related is the toString method. All this is doing is a JSON.stringify, which could just as easily be done without this method.

    Like the formatter, it would be a major version bump for removal though

  3. lholmquist commented on Jun 10, 2020

    @lholmquist
    Contributor

    @lance @grant if either of you haven't started to work on this, i could take a look at breaking the Formatter into its own function

  4. lance commented on Jun 10, 2020

    @lance
    Member

    @lholmquist all yours

  5. grant commented on Jun 10, 2020

    @grant
    MemberAuthor

    ☝️ All yours.

  6. lholmquist commented on Jun 18, 2020

    @lholmquist
    Contributor

    Probably going to hold off on this since it will be part of #226

    should we close?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions