Effect CommunityEC
Effect Communityβ€’5mo agoβ€’
58 replies
nemmtor

Exploring JSX with Effect and Custom Parsers

How crazy is this idea?
Probably would need to write some custom jsx parser πŸ€”.


const Foo = () => Effect.gen(function*(){
  const service = yield* FooService(); // Dependency injection
  const whatever = yield* service.whatever;
  const something = yield* service.something;

  if(!whatever){
    return yield* new SomeError();
  }

  if(!something){
    return yield* new SomeCriticalError();
  }
  
  return <Bar onClick={service.foo} />
});


const Bar = () => Effect.gen(function*(){
  return(
    <Foo
      pipe={Effect.catchErrorTag('SomeError', () => <SomeFallback />)}
    />
});


renderEffect(
  <Bar
    pipe={
      Effect.catchAll(() => <UnexpectedError />),
      Effect.provideService(FooService, FooService.Live)
    }
  />
);
Was this page helpful?