Breeze / breeze-client

Breeze for JavaScript clients
MIT License
38 stars 16 forks source link

PostInitializer sequence order #54

Open graphicsxp opened 3 years ago

graphicsxp commented 3 years ago

I have a postInitializer in my breeze entities and i've noticed that I'm running into an issue with this.

Let's say I have entityAwhich has a collection property of entityBobjects.

Both entities have their own PostInitializer function registered. However the PostInitializer of entityBis called after the one of entityA, which means when the postInitiliazer method of entityA is fired, the collection of entityBobject is null

 postInitializer(metadataStore: MetadataStore) {

    metadataStore.registerEntityTypeCtor(
      'entityA',
      entityA,
      (data: entityA) => {
          // trying to do things with data.entityB but it is null at this point.
      });
  }

After that the postInitializer of entityB is called and after that the collection property on entityA is populated but it is too late at this stage to do any post-processing.

How can we force entityBto be initialized before entityA?

steveschmitt commented 3 years ago

Good question! I don't know what determines the order of the postinitializers. Have you tried re-arranging the code that calls them?

graphicsxp commented 3 years ago

I have tried that indeed. I changed the order in which they are registered in my registration-helper class (generated with breeze generator) and this had no effect at all. Anything else I could try ?