The execution of this code is confusing me:
class RecipeListViewModel: ObservableObject {
@Published var recipeList = [RecipeViewModel]()
init(){
RecipeRepository.$allRecipeVMs.map { recipes in
recipes.map { recipe in
recipe
}
}
.assign(to: &$recipeList)
}
}
My understanding was that SwiftUI publishers are uni-directional, meaning that when RecipeRepository.allRecipeVMs
is modified recipeList
is too. However, the behaviour I'm seeing is that When recipeList
is updated, RecipeRepository.allRecipeVMs
is also updated. I've tried to find documentation on this but can't seem to find anything.
Here is the RecipeViewModel
class, not sure if it's useful:
class RecipeViewModel : Identifiable, ObservableObject, Hashable{
var id = UUID().uuidString
@Published var recipe: Recipe
init(recipe: Recipe){
self.recipe = recipe
}
}