1

I have created a js bin outlining some of the details.

My question is, without using Ember Data, how can I implement a "class" in ember that can observe all bindings, and on a change to the model, convert the observed property to a URL based off of the keys path to the data in the model object. Then, I can take it from there.

Please refer to the js bin as there is an application setup there, and ready for you.

To Recap. I am attempting hook into the model, and on any change, detect what was changed, what the key path is to the data that was changed is, grab the new data and convert the key path into a url.

I will also provide a preview of the model and a sample url to the model here.

Obj = Em.Object.create({
    a: 'a',
    b: 'b',
    c: 'c',
    d: Em.A([
        {
            da: 'da',
            db: 'db',
            dc: 'dc'
        },{
            da: 'da',
            db: 'db',
            dc: 'dc'
        }    

    ])      
});

Let's say that the path Obj.d[0].db gets updated with new data. then the url would be

http://api.domain.com/d/0/db/

Some references that have helped me a bit:

Ember.js: Observing all object properties

How can an observer find out the before and after values of the observed property in Ember.js?

Community
  • 1
  • 1
Charlie
  • 376
  • 1
  • 10
  • Can you tell us why you need this? I suspect there's a better way to design whatever it is you're trying to accomplish. Do you know specifically what keys you want to observe beforehand? I.e., will you know the names of the properties beforehand, or do you want a less "hard-coded" solution? I ask since your example uses dummy variable names. – Sherwin Yu Jan 29 '14 at 16:06
  • I do know the key names before hand, but i will not know how many indexes are in any of the arrays, I will have to count them. A less hard coded solution would definitely be ideal as it seems to me to be more extensible. I have a JSON data structure that I need to sync in real time (node, express, socket.io) with other users via a web socket. I can obviously send the entire data structure up after a debouncing period but that is inefficient and has a greater potential for conflicts. I would like to assign every field a unique url so the payload goes from 20-80kb (big document) to < 1kb. – Charlie Jan 29 '14 at 23:36
  • Also, The system needs to be designed for 5,000 + simultaneous users. – Charlie Jan 29 '14 at 23:38
  • Do you also expect the objects to be nested arbitrarily deep of arrays and objects, resulting in URLs like `api.domain.com/d/0/4/a/nestedkey/` etc, or is it simply to the level you specify in the question? – Sherwin Yu Jan 30 '14 at 03:11
  • To clarify, you effectively want to keep a singleton JSON object in-sync across all your users, and you're using the server to do the synchronization. So am I correct to say the real question is how to determine the path of the property that changes, and that the construction of the URL isn't relevant to how you interact with Ember.? – Sherwin Yu Jan 30 '14 at 03:25
  • Yes, Arbitrarily deep. Yes, the construction of the URL will be done in plain javascript. But the URL is relevant to Ember in the sense that an end user will effectively be updating an Ember Model via some control, (a combination of input, checkboxes, text areas etc...) Yes the question is, how do you determine the path of the property that changes. Once I have that, the URL construction is a piece of cake. I only included this as part of the question so that you can have some insight as to what the end result will be. And, thank you, by the way. – Charlie Jan 30 '14 at 15:16
  • Edit, not Arbitrarily deep, but it would be nice to work that out as well. :) – Charlie Jan 30 '14 at 15:23
  • I get what you are asking now, I have to conform to server side spec, this means I need to give them a URL (REST) as part of the object sent through the socket. So Spec is, every data has a unique URL. I can't change that. – Charlie Jan 30 '14 at 15:29

0 Answers0