These are chat archives for canjs/canjs

17th
Oct 2017
Ivo Pinheiro
@ivospinheiro
Oct 17 2017 22:55

Hi all,
I'm struggling with can-connect using real-time behavior.
Please check the following example:

  var todoAlgebra = new set.Algebra(
    set.props.id("id")
  );

  fixture({
    [`DELETE /api/todos/{id}`]: (request, response) => {
      return response(200, {}); //Doesn't work
      //return response(204); //Doesn't work
      //return response(200, request.data); //WORKS FINE!!!
    },
    ["GET /api/todos"]: (request, response) => {
      response(200, [
        { name: "mow lawn", complete: false, id: 5 },
        { name: "dishes", complete: true, id: 6 },
        { name: "learn canjs", complete: false, id: 7 }
      ]);
    }
  });

  var Todo = DefineMap.extend({
    id: {type: "string"},
    name: {type: "string"},
    complete: {type: "boolean", value: false}
  });

  Todo.List = DefineList.extend({
    "#": Todo
  });

  baseMap({
    url: "/api/todos",
    Map: Todo,
    List: Todo.List,
    name: "todo",
    algebra: todoAlgebra
  });

  let todosList;
  Todo.getList({}).then(todos=>{
    todosList = todos;

    todosList.on("remove", ()=>{
      console.log("Item removed from the list");
    });

    todosList.get(0).destroy().then(()=>{
      console.log("Item destroyed");
    });
  }, error=>{
    console.log(error);
  });

I'm expecting the todoList remove handler to be called whenever a todo is destroyed, but it seems to depend from the server response.

I have the following questions:

  • is it expected that the DELETE always returns something?
  • why the 204 http-code doesn't work?