I am trying to adapt the idea of a normalized application state to Angular 
2 (see normalizr <https://github.com/gaearon/normalizr>). Here's an example 
of normalized state for maintaining customer orders. Note that there are no 
nested entities and arrays simply keep references to the associated 
entities.

var filledOrders  = [1, 3, ...];
var delayedOrders = [2, 7, ...];

var orders = [
    {
        id: 1,
        customer: 'johns',
        items: [...]
    },
    {
        id: 2,
        customer: 'stevek',
        items: [...]
    },
    {
        id: 3,
        customer: 'maryb',
        items: [...]
    },
    ...
]

var customers = [
    {
        id: 'johns',
        firstName: 'John',
        lastName: 'Smith',
        ...
    },
    {
        id: 'maryb',
        firstName: 'Mary',
        lastName: 'Brown',
        ...
    }
]

However when I am trying to render, say, filled orders, the view template 
needs a join of  filledOrders, orders and customers. Something like this, 
you may call this the "view model":

var filledOrders = [
    {
        id: 1,
        customer: {
            id: 'johns',
            firstName: 'John',
            lastName: 'Smith',
            ...        
        },
        items: [...]
    },
    {
        id: 3,
        customer: {
            id: 'johns',
            firstName: 'John',
            lastName: 'Smith',
            ...        
        },
        items: [...]
    },
    ...    
]

Two questions:

   1. Is there a convenient place in the Angular2 component lifecycle where 
   I can construct this model on the fly?
   2. Can the change detection be still tied to the normalized state and 
   not to the view model?

Naresh

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to