rpaschoal / ng-chat

💬 A simple facebook/linkedin lookalike chat module for Angular applications.
MIT License
155 stars 92 forks source link

Problemas na hora de fazer a requisição de dados #110

Closed Nesbox314 closed 4 years ago

Nesbox314 commented 5 years ago

Olá, Rafael, eu procurava um componente bacana de chat para a implementação em um sistema particular, e achei o seu muito legal e servia muito bom nos meus propósitos, porém estou enfrentando um problema.

O sistema em desenvolvimento se baseia em Angular e uma API em Spring, ou seja, as requisições de dados que eu tenho de fazer, são métodos que vem de um serviço chamado BaseService, logo, eu obrigatoriamente preciso extender o BaseService no MyAdapter, para fazer as requisições e conseguir utilizar o chat e todas as suas funções.

Meu objetivo era pegar o MyAdapter e extendê-lo, porém, até onde eu entendi o MyAdapter tem por obrigação extender o ChatAdapter. Tentei de várias formas driblar essa estrutura, resultado: todas falhas.

Por fim, eu gostaria de saber se há alguma forma de eu conseguir usar meus métodos trazendo o ChatAdapter de outra forma.

Segue imagem do BaseService baseservice

rpaschoal commented 5 years ago

O sistema em desenvolvimento se baseia em Angular e uma API em Spring, ou seja, as requisições de dados que eu tenho de fazer, são métodos que vem de um serviço chamado BaseService, logo, eu obrigatoriamente preciso extender o BaseService no MyAdapter, para fazer as requisições e conseguir utilizar o chat e todas as suas funções.

Por que voce precisa extender o seu BaseService para fazer requisicoes? Voce pode injetar dependencias no seu adapter. Voce pode criar um servico de Chat separado, por exemplo ChatService que extende BaseService e registrar como provider e passar via construtor no seu adapter para o ng-chat.

Eu vou investigar fazer uma refatoracao do adapter para ser uma interface ao inves de uma classe abstrata, acho que nao ha necessidade do contrato utilizar uma classe abstrata e talvez tenha sido uma falha de design inicial para o componente.

Quando criar outros "issues" aqui no repositorio eu sugiro que o faca em Ingles ao inves de Portugues.

Nesbox314 commented 5 years ago

Muito obrigado Rafael, com certeza vou tentar implementar desse jeito, se você conseguir refatorar o projeto, eu agradeceria infinitamente se você me avisasse.

OBRIGADO!!!!

Ps: Desculpa escrever o Issue em PT-BR.

rpaschoal commented 4 years ago

Hi @Nesbox314 ,

I've been thinking about this one and if we could refactor the ChatAdapter to an interface.

The reason why we have an abstract class in place instead of an interface for the adapter is that we want to expose these runtime bind methods and expose it to the users of ng-chat: https://github.com/rpaschoal/ng-chat/blob/d812e92f7acdee4584126025a841806f9b423b61/src/ng-chat/ng-chat.component.ts#L263-L265

Looking on a hindsight probably not the best design but it seems to be working for majority of people using this module.

All further behavior of this module have been segregated as interfaces and this is the plan moving forward if more features are to be added.

I believe that for the sake of not introducing breaking changes for users of the module we'll have to keep it like this.

One thing I could do though to improve the public API is to add an @internal decorator to these lines which I'll look into doing with the next release: https://github.com/rpaschoal/ng-chat/blob/d812e92f7acdee4584126025a841806f9b423b61/src/ng-chat/core/chat-adapter.ts#L29-L31

I'll be closing this one as no further action will be taken apart from the @internal decorators.