Pass model to child components as reference or create global variable

227
February 08, 2018, at 11:55 PM

I have SPA built using dojo with structure like:

App    
- > Parent Component
    - > Child component
        - > Child component

For my Parent component I defined model and create instace of it in component's constructor.

Now in my parent component I create instances of children like this:

const tabs = [
            new Head({model: model}),
            new Main({model: model}),
            new Statement({model: model})
        ];

So I access model in children components with this keyword.

Wouldn't it be better to create instance of model for current component in some global namespace and access it in all child components like app.model or just global variable model just to avod of passing reference through cascade of nested components?

Which approach is better an why?

Rent Charter Buses Company
READ ALSO
How to handle form input with AJAX GET

How to handle form input with AJAX GET

This is my first attempt to create a page with HTML and javascript

261
jQuery - Value of TEXTAREA is 'undefined'

jQuery - Value of TEXTAREA is 'undefined'

So I have a div with an id = editor-email

260
how to correctly implement async event handlers in browser

how to correctly implement async event handlers in browser

gents I am struggling with this problem on an older project I have for a whileI also created a sample repo : https://github

241
Vue-js and Vuex: View not being updated

Vue-js and Vuex: View not being updated

I am using Vuejs and Vuex to play around withCurrently i have an issue updating the view (vuejs) after an AJAX call has been fired

307