Skip to content

api proposal: add "service" method #5

@betula

Description

@betula

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions