Yarikx / reductor

Redux for Android. Predictable state container library for Java/Android
Apache License 2.0
463 stars 27 forks source link

Pass-by-reference Detected in State #38

Closed ZonZonZon closed 6 years ago

ZonZonZon commented 6 years ago

In your article (part 2) there is a State class example:

public class AppState { public final List todoItems; public final TodoFilter filter;

  public AppState(List<TodoItem> todoItems, TodoFilter filter) {
    this.todoItems = todoItems;
    this.filter = filter;
}

}

If I'm not mistaken, this will not freeze the state of an app, because passed parameters are references and this.todoItems copies a reference. Thus after some time reference source changes and so does my final this.todoItems.

There should be a kind of clone with a new object creation. Doing it in reducer is not obvious and can be source of errors. State class is a better place to my mind.

ZonZonZon commented 6 years ago

Missed Pcollections part in Prologue. Sorry.