GithubHelp home page GithubHelp logo

TypeScript support about cote HOT 9 CLOSED

dashersw avatar dashersw commented on May 22, 2024
TypeScript support

from cote.

Comments (9)

nykula avatar nykula commented on May 22, 2024 2

Published definitions as DefinitelyTyped/DefinitelyTyped#17373

Install with yarn add @types/cote

The utils I mentioned earlier make use of the definitions but are a different thing

May be more useful if your usage of cote is similar to mine

I adapted examples and published the package as well: https://github.com/makepost/nyan-cote

from cote.

robophil avatar robophil commented on May 22, 2024 1

True @dashersw, but you can publish typings for your projects without writing it in typescript.
I see a lot of that now when using vscode. IDE's are smart to work with typings. eg express, node, etc see typings, definatelytyped

from cote.

dashersw avatar dashersw commented on May 22, 2024 1

@robophil exactly! that's what I understood from "typescript support", just adding the typings. cote is written in ES6, and we will never rewrite it in TS.

from cote.

robophil avatar robophil commented on May 22, 2024

with node supporting es6 a bit more with each release, would that still be necessary?

from cote.

dashersw avatar dashersw commented on May 22, 2024

@robophil it would bring in type safety and code completion for TS users and modern IDEs.

@dulichan it's not a priority for me right now, but I would love if someone tackled this problem.

from cote.

nykula avatar nykula commented on May 22, 2024

Have a look at https://github.com/makepost/microservice-playground

Responder and Requester remind me of Service and Inject from typedi

So I applied decorators, metadata, proxies and async/await to get a similar API

Brings my services type safety and code completion in VS Code

Has Publisher, Requester, Responder and Subscriber

I want to focus on logic and avoid introducing extra names

So it uses names of decorated classes as both key and name

The latter, name, is prefixed by e.g. Publisher--

If anyone is interested I can make a npm package

from cote.

dulichan avatar dulichan commented on May 22, 2024

from cote.

dashersw avatar dashersw commented on May 22, 2024

Hello @makepost, thanks for the immense effort! This is a nice beginning, and I would have loved if we worked together on this — the typings have some errors and shortcomings and now since they are in DefinitelyTyped, they are kind of the go-to typings.

Here are some of my initial observations:

  • There should be no rigid definition of a cote.Action other than the requirement that it's an object (record types in JSDoc) with a type property. It's not an internal class and shouldn't be called as if so.
  • Advertisement differs from type to type, subscribesTo shouldn't be an option for a responder.
  • There are about 10 other discoveryOptions and now they are hidden.
  • The classes actually inherit from EventEmitter2 and therefore also expose its API.
  • There are missing classes: TimeBalancedRequester and PendingBalancedRequester.
  • As you've mentioned this only takes into account Promises, but the API also works with callbacks.
  • There are certain pre-built events that the user can listen to on every component, like cote:added and cote:removed.

Finally, about nyan-cote: key's can't be automatically deduced from class names, because if a Requester and a Responder have different keys, they won't be able to communicate.

from cote.

nykula avatar nykula commented on May 22, 2024

Thanks for the feedback

@types/cote has just updated

I addressed all the issues you mentioned

How do I improve nyan-cote?

Example services follow cote README and are able to communicate

For Responder, the key is its own class name

For Requester, the key is the class name of the Responder it talks to

from cote.

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.