Closed AriaFallah closed 8 years ago
You could use:
var a = require('lodash/fp/assign');
a([1,2,3], [4,5,6])
// => { '0': 4, '1': 5, '2': 6 }
var a = require('lodash/fp/assign').convert({ 'immutable': false });
a([1,2,3], [4,5,6])
// => [ 4, 5, 6 ]
@jdalton Ah thanks for the advice! I realized though that trying to mutate things using lodash/fp
is not a great idea, and have adopted something a bit more appropriate now.
Thanks anyways 😄
and have adopted something a bit more appropriate now
What did you adopt?
@jdalton
Back when I was using .chain()
and not lodash/fp
I had this weird system of having an observable array behind the scenes, and then exposing a normal array wrapped in chain. This was because if I tried to wrap the observable in chain it didn't work at all. Then when the exposed chained array was mutated I would propagate the changes to the underlying observable. It was pretty hacky, but it worked.
When I switched to passing lodash/fp
methods to flow
at first I was confused on how to mutate the exposed array with lodash/fp
in order to be able to pass on the changes to the underlying observable. I then had the epiphany that since I didn't need chain
anymore I also didn't need the old hacky system.
I got rid of the middleman array, and made it so the store actually returned itself. Then it was trivial to directly mutate the store directly using the array prototype methods you would normally use.
store('x', [filter({ condition: true }), take(5)]) // read from the store using lodash/fp methods
store('x').push({ condition: false }) // mutate the store like you would an array
Does that make sense?
Ah ok!
Addressing #9
This breaks the current API.
Instead of
it is now
For chaining, instead of
it is now
A caveat is that
assign
is not really great in lodash/fp https://github.com/lodash/lodash/issues/2275 so mobx-store now exportsmutate
instead of