mitosis icon indicating copy to clipboard operation
mitosis copied to clipboard

core: add MitosisComponent.props

Open PatrickJS opened this issue 2 years ago • 2 comments

I think the code will be a lot simpler in the generators if we provide more metadata on the props. For example in angular we want to know if it's a function and if it's being invoked. or in React if it's going used in ref binding.

I was something something like

type PropType = 
  | 'function'
  | 'string'
  | 'boolean'
  | 'undefined'
  | 'null';

// metadata on how it's being used
type PropUsed = 
  | 'binding'
  | 'invoked'
  | 'binding.ref' // forwardRef
  | 'function'
  | 'onMount'
  | 'onInit'
  | 'onUnMount'
  | 'onUpdate'
  | 'onUpdate.dep';

interface MitosisProp {
  type: PropType;
  used: PropUsed[];
  code: string;
}

PatrickJS avatar Jun 10 '22 17:06 PatrickJS

Can you please provide a detailed example of how we use MitosisComponent.props

decadef20 avatar Jun 11 '22 07:06 decadef20

@PatrickJS Debating whether we can keep this logic in generators for now, until we see enough need for it to be permanently embedded in the JSON schema. That way, we can gather more use-cases from more generators about what info we need to store, and the schema will be more accurate.

Unless doing it in the generators is a lot harder or hacky than in the babel transform of the JSX parser, in which case it makes sense to move it there earlier.

My main concern is not crowding up the component JSON and having data in there that can easily be derived from other parts of the JSON (by inspecting both the props and the lifecycle hooks code for example)

samijaber avatar Jun 13 '22 18:06 samijaber