knockout-postbox icon indicating copy to clipboard operation
knockout-postbox copied to clipboard

When publishing a value with a circular reference, a 'cyclic object value' error is thrown

Open stijnherreman opened this issue 7 years ago • 14 comments

When publishing a value with a circular reference, a 'cyclic object value' error is thrown. This is because of the serialization that happens to fill topicCache.

Code to reproduce:

const foo = {
  id: "foo",
  bar: ko.observable()
}
const bar = {
  id: "bar",
  foo: ko.observable()
}
ko.postbox.subscribe("foo", function() {
  console.log("foo was published");
})

ko.postbox.publish("foo", foo); // console: foo was published

foo.bar(bar);
ko.postbox.publish("foo", foo); // console: foo was published

bar.foo(foo);
ko.postbox.publish("foo", foo); // TypeError: cyclic object value

Is this something that can be solved by the library, or is it something I need to solve in my code?

stijnherreman avatar Sep 01 '16 11:09 stijnherreman