# Changing doc.attrs?

**URL:** https://discuss.prosemirror.net/t/changing-doc-attrs/784
**Category:** Uncategorized
**Created:** [May 18, 2017, 8:22am UTC](https://discuss.prosemirror.net/t/changing-doc-attrs/784 "2017-05-18T08:22:51Z")
**Posts on this page:** 1
**Showing post:** 16

<div class="post-metadata">

### Author: ![Jordan](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Jordan](https://discuss.prosemirror.net/u/Jordan)
#### Post date: [October 6, 2017, 9:01pm UTC](https://discuss.prosemirror.net/t/changing-doc-attrs/784/16 "2017-10-06T21:01:22Z")

</div>

Hi johanneswilm - I’m happy to share, but I haven’t implemented this in a generic way, so it’s not particularly useful verbatim. It’s pretty simple though:

```auto
class AddTodo extends Step {
  constructor(todo) {
    super();

    this.todo = todo;
  }

  apply(doc) {
    doc.attrs.todos.push(this.todo);

    return StepResult.ok(doc);
  }

  invert() {
    return new RemoveTodo(this.todo);
  }

  map(mapping) {
    return this;
  }

  toJSON() {
    return {
      stepType: "addTodo",
      todo: this.todo
    };
  }

  static fromJSON(json) {
    return new AddTodo(json.todo);
  }
}
Step.jsonID("addTodo", AddTodo);

```

which is used as:

```auto
state.tr.step(new AddTodo(todo));

```

Modifying the doc.attrs value directly seems a bit wrong, but appears to work as desired. Note that I’m only ever using this in conjunction with a step that actually modifies the document content (in a standard way), so I’m not sure how well this would work if it’s the only step being applied.

---

_[View the full topic](https://discuss.prosemirror.net/t/changing-doc-attrs/784)._
