Code Monkey home page Code Monkey logo

Comments (10)

sam-goodwin avatar sam-goodwin commented on August 15, 2024 1

I was thinking we could borrow the mixin trick from shapes here.

export class FlightCreated extends Event("FlightCreated", object(...)) {}

new FlightCreated({ ... })

from stochastic.

sam-goodwin avatar sam-goodwin commented on August 15, 2024 1

Let's discuss this item next time we meet. I'll try and provide a write up of the DX I'm thinking about

from stochastic.

ryan-mars avatar ryan-mars commented on August 15, 2024

This seems like too much boiler plate. Need helpers for defining and creating events. Not sure what the exact DX should be though. I guess it would be nice to have a create(type, {...}) helper for instances. Could not new Event() take the structure of payload and save a step?

const FlightCreated = 
    object({ 
      id: string(),
      time: string(),      
      type: literal("FlightCreated"), 
      payload: object({
        flightNo: string(),
        aircraftType: string(),
        origin: string(),
        destination: string()
      })
    })
const FlightCreatedEvent = new Event("FlightCreated", FlightCreated);

//... and then to return an actual event
{
  id: KSUID.randomSync().string,
  time: new Date().toISOString(),
  type: "FlightCreated",
  payload: {
    ...command,
  },
},

from stochastic.

ryan-mars avatar ryan-mars commented on August 15, 2024

Mixins could work, provided people understand they should not be further extended. I kinda wonder if we should just provide a function that returns the class without having to extend the mixin Function. Is there something special about class ... extends MixinFunc that couldn't be done with const FlightCreated = Event("FlightCreated", object(...))?

How do we avoid confusing the thing that is an Event (in the graph), with an instance of an Event (data), with a helper function for creating instances? The DX here is not obvious to me. I apologize if I'm not making a lot of sense here. I'm finding it difficult to express my instincts.

from stochastic.

sam-goodwin avatar sam-goodwin commented on August 15, 2024

The function returns a Class, whether the developer extends that or not is up to them. An instance of that class is an event value. I think extending it makes sense to extend it since then you have a type for the event data.

class MyEvent extends Event(..) {}

type MyEventSchema = typeof MyEvent // equiv. in Java would be MyEvent.class

type MyEventData = MyEvent

from stochastic.

ryan-mars avatar ryan-mars commented on August 15, 2024

Should we be using type or kind to discriminate at runtime?

from stochastic.

sam-goodwin avatar sam-goodwin commented on August 15, 2024

Maybe we should borrow from graphql, __typename.

from stochastic.

ryan-mars avatar ryan-mars commented on August 15, 2024

I'm not opposed to __typename I want whatever will be the least confusing and most obvious. Since GraphQL shares it could that complicate things for developers at some point if they bolt GraphQL onto the front of a stochastic app and begin passing Events around or fetching from Read Models?

🤔

from stochastic.

sam-goodwin avatar sam-goodwin commented on August 15, 2024

We made some significant progress in https://github.com/stochastic/stochastic/pull/31

Still some TODOS:

  • Re-visit the payload boiler-plate in DomainEvent
  • fields that are optional or defaulted are not reflected as optional in the constructor.

from stochastic.

ryan-mars avatar ryan-mars commented on August 15, 2024
  • fields that are optional or defaulted are not reflected as optional in the constructor.

Created #37 Shapes: Shape fields that are optional or defaulted are not reflected as optional in the constructor to track this

from stochastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.