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

api proposal: add "service" method #5

Open
betula opened this issue Jan 9, 2023 · 0 comments
Open

api proposal: add "service" method #5

betula opened this issue Jan 9, 2023 · 0 comments

Comments

@betula
Copy link
Member

betula commented Jan 9, 2023

The "service" method makes a Proxy.

// Old one

const GateService = () => {
  const line = createLine('message');

  return {
    line
  }
}

export const initGate = () => provide(GateService);
export const getGate = () => provide(GateService).line;

// But better

export const gateService = service(() => {
  const line = createLine('message');

  return {
    line
  }
})

export const initGate = gateService.init;
export const getGate = () => gateService.line; // autoinit if not exists here

// And we can use it directly

import { gateService } from './gate-service';

// ...

Next improvement: add automatic getters for all '$' dollar started properties.

const connectService = service(() => {
  $hasError = box(false);
  // ...
  return {
    $hasError
  }
});


console.assert(connectService.hasError === false) // its will be greatly helpfull

It should be not a proxy -> it should be added real getters.
hmmm, think about more. ...I see performance problems with proxy
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

No branches or pull requests

1 participant