Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy adapter instead of having to manually create operations #40

Closed
agubler opened this issue Jul 30, 2018 · 0 comments
Closed

Proxy adapter instead of having to manually create operations #40

agubler opened this issue Jul 30, 2018 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@agubler
Copy link
Member

agubler commented Jul 30, 2018

@matt-gadd commented on Tue Jun 26 2018

Enhancement
If we leverage Proxies, I think we can just about track the appropriate paths and changes to allow the user to simply do object and array accessing and setting rather than having to use the get helper and returning the associated operations.

The following would go from:

function calculateCountsCommand({ get, path }: CommandRequest) {
	const todos = get(path('todos'));
	const completedTodos = todos.filter((todo: any) => todo.completed);
	const operations = [
		replace(path('activeCount'), todos.length - completedTodos.length),
		replace(path('completedCount'), completedTodos.length)
	];
	return operations;
}

to:

function calculateCountsCommand(state) {
	const completedTodos = state.todos.filter((todo: any) => todo.completed);
	state.activeCount = state.todos.length - completedTodos.length;
	state.completedCount = completedTodos.length;
}

This would work via the state object being passed in being Proxy wrapped and everything off it. Every time a set is called we'd create the appropriate operation.

A few caveats:

  • Won't work in IE11 (so we need to support the existing way)
  • The functions no longer take an input and return an output (would have to think about the testing implications)
  • Performance?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants