Hacker News new | past | comments | ask | show | jobs | submit login

One should use what is necessary and no more. If server side templates work for you - great.

My rule of thumb: if I need to do more then a trivial amount of DOM manipulation then I will use a framework, because otherwise I will end up writing my own anyway (which I can easily do) which wastes development time.

For projects with several developers a framework can help maintain common coding style and reduce ramp up time for new hires.

Also, good frameworks come with nice tooling that make for more productive development. For example, Vue + Vuex and the Vue browser plugin are great for inspecting the state and observing state transitions.

An example of my use case: I have a non-SPA app that receives various data via Websocket and the view is immediately updated. Several components take this same data and render it in different ways. Vue is excellent for this. I still use templating on the server side for the basic page structure.




Could you add the lines needed to the above example to make the user list grow / shrink real time via websockets?

Would be interested to see how you would implement that.


Pseudo-ish code because I’m typing from my phone.

Vuex code as per docs to create state.stuff and mutations.update_suff() then in main Vue instance

    mounted () {
      this.$socket.subscribe(‘stuff’, data => {
        this.$store.commit(‘update_stuff’, data);
      });
where $socket is a subscriber client I wrote wrapped as a Vue plugin.

Then inside the components

    computed () {
      stuff () {
        return this.$store.state.stuff;
      }
    }
then use stuff as in your example.

So very simple, and nothing that I couldn’t do without Vue but it takes care of the boring DOM manipulations and using the browser extension during development I can watch state change (which becomes interesting when there are multiple subscriptions with data combined).


So the first step towards your solution would be to include vuex? Like this?

    <script src="/path/to/vuex.js"></script>
And then?

What are mounted() and computed()? They look like methods of a class?




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: