M
M
magary42016-10-07 22:25:08
JavaScript
magary4, 2016-10-07 22:25:08

How to design this?

there is a REST API
there is a service let's call it InfoService which makes REST requests and receives callbacks the
controller looks something like this

funtction controller()
{
    scope.list = InfoService.getItems();
    scope.remove(id) {
         InfoService.remove(id);
    }
}

there is a ul on the page where scope.list is rendered. I don't understand how to organize the logic after let's say the service's remove function is called. There will be a request to REST and after a while the answer will come. how further should the service notify the controller that scope.list has changed and re-render the ul ??
now I have some callback-hell
now it all works on angularlight but it is very possible that it will be rewritten to another framework,
you can also advise which framework is best to take. need:
-databinding
-dependency injected

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2016-10-07
@magary4

promises. They even exist natively in the latest versions of top browsers.

V
Vladimir Sergeevich, 2016-10-08
@VladimirZhid

Do you need a framework for such tasks?
I just thought of making the service and controller the usual js objects
, plus using some simple templating engine

In this case, I advise React + Redux
Very satisfied, after the backbone and a quick look at ember (Good, but real mastodon)
If you are interested in the comments, I will throw off links to books on react and redux ... you can actually start writing something in a couple of evenings, understanding will come of course later ... but the start is relatively fast

A
Anton, 2016-10-08
@SPAHI4

Try Angular 2 + Apollo stack

S
Shane Matte, 2017-02-07
@mattedev

I haven't worked with Angular for a long time. But you can connect with redax. Make requests through exios, it returns promises. You put it in a store, and the store is already tied to the component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question