Assertion failed: you must use Ember.set () to set the property (of the [Object Object]) to `[object Object]`

I am trying to integrate the Javascript library that I create using EmberJS.

An example of almost working integration: https://github.com/pubnub/open-chat-framework/blob/ember/examples/ember

The library returns a single object with many nested objects. The library is based on network events, so child objects are updated periodically without user input. Updated fire events that you can listen to.

This causes problems for EmberJS, because Ember requires that each property update be done with a help Ember.set()that my library does not use.

A library is a general-purpose JS library, so I refuse to add special Ember code to it. I am wondering how to solve the above error without rewriting my library.

How can I wrap an event-based library the way Ember would like? I previously tried global computing and the Ember service.

In other examples, I saw people exchange each library method with special Ember code. It seems repetitive.

Is it possible to manually inform Ember of changes to the root object and ignore Ember all other changes? Meaning, can I have ember NOT observe changes and manually tell ember when something changes?

The library includes the source of the root event, which is notified of all changes to any object in the tree.

ember-cli: 2.11.1
node: 6.7.0
os: darwin x64
+4
1

, .

, ember.

:

import Ember from 'ember';

export default Ember.Controller.extend({

    OCF: null,
    me: null,
    messages: [],
    messageInput: '',
    init: function() {

        this._super(...arguments);

        // test
        let OCF = window.OpenChatFramework.create({
          rltm: {
              service: 'pubnub', 
              config: {
                  publishKey: 'pub-c-07824b7a-6637-4e6d-91b4-7f0505d3de3f',
                  subscribeKey: 'sub-c-43b48ad6-d453-11e6-bd29-0619f8945a4f',
                  restore: false
              }
          },
          globalChannel: 'ocf-demo-ember-2'
        });
    this.set('OCF', OCF);

        // create a user for myself and store as ```me```
        let me = this.get('OCF').connect(new Date().getTime());
    this.set('me', me);

        this.get('me').plugin(window.OpenChatFramework.plugin.randomUsername(this.get('OCF').globalChat));

        this.get('OCF').globalChat.on('message', (payload) => {
          console.log(payload)
          this.get('messages').pushObject(payload);
        });

    },
    actions: {
        sendChat: function() {
            let messageInput = this.get('messageInput');
            if(messageInput) {

                this.get('OCF').globalChat.send('message', {
                    text: messageInput
                });

                Ember.set(this, 'messageInput', '');

            }

            return false;

        }
    }
});
0

Source: https://habr.com/ru/post/1671430/


All Articles