polymer_elements icon indicating copy to clipboard operation
polymer_elements copied to clipboard

Cannot add dart objects to Firebase-Collection data

Open vimalraj-a opened this issue 10 years ago • 7 comments

I have simple PODO like

class Todo{
    String title;
    bool isComplete;
    Todo();
    Todo.basic(this.title,this.isComplete);
}

Html:

<firebase-collection id="firebase" log="true"
                location="{{location}}"
                data="{{todos}}"></firebase-collection>

Dart:

@reflectable
AddNew(Event e,Object o){
     add('todos',new Todo.basic("new todo",false));
}

When I add new Todo object to todos List, new item not send to firebase.

vimalraj-a avatar Nov 21 '15 14:11 vimalraj-a

As workaround you can try:

add('todos',convertToJs(new Todo.basic("new todo",false)));

zoechi avatar Nov 21 '15 16:11 zoechi

Above solution is not working. convertToJs return an Js object.

Is it possible to convert Dart Object to Map in polymer? If i add map to firebase-collection, it gets updated in firebase.

vimalraj-a avatar Nov 22 '15 06:11 vimalraj-a

I think this caused by https://github.com/dart-lang/polymer-dart/issues/618. As long as your class extends JsProxy then it should work once that issue is fixed.

jakemac53 avatar Nov 23 '15 15:11 jakemac53

Thanks @jakemac53 . I tried with extending JsProxy and using JsProxy as Mixin. Both ways not solving the issue.

here is my dart Todo class PODO - Case1:

class Todo extends JsProxy{
    String title;
    bool isComplete;
    Todo();
    Todo.basic(this.title,this.isComplete);
}

PODO - Case2:

class Todo extends Object with JsProxy{
    String title;
    bool isComplete;
    Todo();
    Todo.basic(this.title,this.isComplete);
}

vimalraj-a avatar Nov 24 '15 05:11 vimalraj-a

The fields should also be annotated with @reflectable

zoechi avatar Nov 24 '15 05:11 zoechi

Yes @zoechi. You are right I need to add @reflectable annotation to fields.

Still I am not able to send todo object to firebase. I can see that convertToJs function returns JsObjectImpl object.

here is my dart Todo class PODO - Case2:

class Todo extends Object with JsProxy{
    @reflectable
    String title;
    @reflectable
    bool isComplete;

    Todo();
    Todo.basic(this.title,this.isComplete);
}

add(){
    var _todo = convertToJs(new Todo.basic("new todo",false));
    print('Todo Title : ${_todo['title']}');
    add('todos',_todo);
}

Chromium Console:

Todo Title :new todo

Adding new item to collection with value: Object {__dartClass__: DartObject}__dartClass__: DartObject 
    isCompleted: false
    priority: ""
    title: "vimal"
__proto__: Object

When I checked Firebase data not updated !

vimalraj-a avatar Nov 24 '15 06:11 vimalraj-a

As mentioned above even with JsProxy it won't work because of dart-lang/polymer-dart#618

jakemac53 avatar Nov 24 '15 14:11 jakemac53