qlik-oss / enigma.js

JavaScript library for consuming Qlik's Associative Engine.
MIT License
210 stars 82 forks source link

Allow Connect to existing enigma connection #528

Open konne opened 5 years ago

konne commented 5 years ago

Description

Issues like #304 and #218 are more complex. Why not implement a new connect to that allows to have an existing enima.js connection as parameter. So that you can have your own scoped enigma with Mixins, Interceptors and shemas without a conflict,.. but no new websocket connection, because the existing websockt connection is shared.

Some config like delta, url, createwebsocket are just ignored because they are used from the base connection. There is only one tricky point. If the connection is a sharedConnection the requestID have to be fetched from the main enigma connection and not generated from the own enigma class.

a sample would be:

const config = {
  schema,
  enigma: $scope.model.enigmamodel
  Promise: bluebird,
  mixins: [{ types: ['Global'], init: () => console.log('Mixin ran') }],
};

enigma.attach(config).then((global) => {
  // global === QIX global interface
});
peol commented 5 years ago

Hey @konne! Thanks for the suggestion, it looks interesting and we have discussed similar approaches before. There are a few tricky things we need to figure out:

There are ways around these issues for sure, we'll just have to be careful to not break existing behaviour (and prioritize the feature, of course).

konne commented 5 years ago

Hey @peol, thanks for the longer discussion. I fully understand now the issue of the delta, because if both enigma.js make a call GetObject("IDXX") they get the same handle from the engine back. I thought that they both get a new handle so we don't have that issue. I also understand now the issues around the Request & Reponse Interceptors.

Let us see if we can solve the issue with the FRs #218 #304

ralfbecher commented 5 years ago

I have a couple use cases in Qlik Sense client where I would like to hook in existing enigma session inside of an extension to prevent unnecessary rerenderings because of needless fired Validated or Changed events. An Interceptor would be a very good solution, right before the deltaResponseInterceptor here. There are (probably) some hacky ways to do already but would prefer an official way..

peol commented 5 years ago

@ralfbecher If you connect a new websocket to an existing session you'll cause invalidations in the other websocket anyway, but maybe I'm misunderstanding you? We are currently looking into how to properly expose the enigma.js instance/configuration inside the Sense client; there may be changes needed in this library for that to happen, but it's unlikely (it's more of an implementation detail inside the Sense client).

ralfbecher commented 5 years ago

@peol yes, I didn't meant a new websocket connect but rather a hook into the existing session.

konne commented 4 years ago

@ralfbecher I have discussed that feature already in a longer session. The tricky point is the delta mode and that the new enigma don't know the history of the objects. But I still see the requirement for this feature

ralfbecher commented 4 years ago

@konne that's why I wanted to hook into an existing enigma instance and session..

peol commented 4 years ago

As you know you create an enigma session by enigma.create(), if you want access to this instance it's something that the sense client needs to expose (and working on exposing). It's not a feature in enigma.js per se.