2

Out of the box Entities defined by using $data.Entity.extend will be globally accessible. e.g. in the example taken from JayData's home page Todo will leak.

// Case 1: local item store example from http://jaydata.org/ 
 $data.Entity.extend("Todo", {
     Id: { type: "int", key: true, computed: true },
     Task: { type: String, required: true, maxLength: 200 },
     DueDate: { type: Date },
     Completed: { type: Boolean }
 });

 console.log('Leaks Todo?', typeof window.Todo !== 'undefined');
 //Result: true 

In a JayData forum post I found a reference to $data.createContainer(), which can be used as container during Entity definition. In this case Todo2 won't leak.

// Case2:  creating Todo2 in a container
$data.Entity.extend("Todo2", container, {
    Id: { type: "int", key: true, computed: true },
    Task: { type: String, required: true, maxLength: 200 },
    DueDate: { type: Date },
    Completed: { type: Boolean }
});

console.log('Leaks Todo2?', typeof window.Todo2 !== 'undefined');
//Result: false

Unfortunately after accessing stores there'll be other variables that leak globally even if the Entity itself is associated with a container.

console.log('Before store access: Leaks Todo2_items?', 
            typeof window.Todo2_items !== 'undefined');
            //Result: false

$data('Todo2').save({ Task: 'Initialized Todo2'})

console.log('After store access: Leaks Todo2_items?', 
            typeof window.Todo2_items !== 'undefined');
            //Result: true

Complete fiddle can be found at http://jsfiddle.net/RainerAtSpirit/nXaYn/.

In an ideal world every variable that is created for entities that run in a container would be associated with the same container. Is there an option to accomplish that or is the behavior described in Case2 the best that can be currently accomplished?

RainerAtSpirit
  • 3,723
  • 1
  • 17
  • 18

0 Answers0