Idea: introduce abstraction for computeds with arguments
See original GitHub issueSee https://github.com/mobxjs/mobx/issues/1388#issuecomment-472748989 and https://github.com/mobxjs/mobx/issues/1388#issuecomment-472751685. This could potentially replace createTransformer
as well.
Signature:
memoizedComputed<T>(expression: T, invalidationStrategy?: "auto" | "never" | number = "auto"): T
strategies:
"auto"
: remove entries from the memoization table as soon as they becomeunobserved
"never"
: we don’t care, cache forever (that is, until the computeds and all things they depend on are GC-ed)number
: remove entries after they have not been hit a the specified amount of time. Probably not needed in a first versoin.
Example:
class Todos {
@observable todos = []
private todosByUserCache = new Map()
getAllTodosByUser = memoizedComputed((userId) => {
if (this.todosByUserCache.has(userId))
return this.todosByUserCache.get(userId).get()
const computedFilter = computed(() => this.todos.filter(todo => todo.user === userId))
this.todosByUserCache.set(userId, computedFilter)
return todosByUserCache.get()
})
}
const todos = new Todos()
const myTodos: Todo[] = todos.getAllTodosByUser("17")
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Abstraction (computer science) - Wikipedia
In software engineering and computer science, abstraction is: The process of removing or generalizing physical, spatial, or temporal details or attributes ...
Read more >OOP Concept for Beginners: What is Abstraction? - Stackify
Abstraction is one of the key concepts of object-oriented programming (OOP) languages. Read examples to better handle complexity.
Read more >Abstraction - Isaac Computer Science
This abstraction helps you to understand the LIFO nature of the structure. With more complex data structures, data abstraction becomes more and more...
Read more >What Are Abstractions in Software Engineering with Examples
In short, an abstraction will simplify a process or artifact , by providing what you really need, and hiding the useless details you...
Read more >Presentation 1.2.1 Abstraction
Describe the purpose and concept of abstracting a procedure. • Introduce lists and iteration across lists. • Describe the role of argument ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Released as 5.4.0!
For one-object-argument functions (a User object instead of just the userId in your example) a WeakMap could help automatically cleaning up entries with the argument-object being GCed. It would be like an “extension” to the User indirectly holding a computed member for all his todos without depending on them. I don’t see this working for multiple arguments or primitives though.