You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-7Lines changed: 71 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -895,8 +895,8 @@ I admit I was stumbling on my way to nowhere for a while, desperately searching
895
895
>
896
896
> <em>(Jonnie Hallman)</em>
897
897
898
-
Really intriguing! The solution is cripty dug there (in clear). Read that, and read it again; lucubrate, my little brain; use the Rosetta Stone to decipher Angular's documentation for [PROVIDERS][20].
899
-
The keys here are factory and service providers.
898
+
Really intriguing! The solution is cripty dug there (in clear). Read that, and read it again; lucubrate, my little brain; use the Rosetta Stone to decipher Angular's documentation for [providers][20].
899
+
The keys here are factory and service recipes.
900
900
901
901
> JavaScript developers often use custom types to write object-oriented code.
The `resultsCount`function to me is like simulating a Vue's computed property.
971
971
But, if you rebuild, launch the application, and start a search... WTF? No count!
972
972
973
973
![vuex-in-angular-component][21]
@@ -996,7 +996,7 @@ export default function (fn) {
996
996
997
997
I am wrapping the function in a "safe apply" to avoid possible "$apply already in progress" errors.
998
998
But how to use it? One of many possible solutions follows.
999
-
If you rewrite your component as an ES6 class you can simply import and use it as a module. Here we are still dealing with a classic component, so I a service as a proxy to expose it:
999
+
If you rewrite your component as an ES6 class you can simply import and use it as a module. Here we are still dealing with a classic component, so I will write a service as a proxy to expose it:
1000
1000
1001
1001
**ngVueBridgeCode/services/utilities.js**
1002
1002
```javascript
@@ -1096,7 +1096,7 @@ export default new Vuex.Store({
1096
1096
});
1097
1097
```
1098
1098
1099
-
If you test this code now you can easily see that, when you press the button, nothing happens. Actually nothing happens until you wake Angular up: try pressing the "Add result" button and the change the search string in the input, or press the "Search" button again.
1099
+
If you test this code now you can easily see that, when you press the button, nothing happens. Actually nothing happens until you wake Angular up: try pressing the "Add result" button and then change the search string in the input, or press the "Search" button again.
1100
1100
No black magic here, you are just letting Angular digest the pizza.
The component will render anytime the custom "result-added" event will be triggered. The counter will be now updated everytime you press the "Add result" button. Remember to remove the listener once you destroy the component.
1167
+
Which we could represent graphically as:
1168
1168
1169
-
This way can also ship requirement #3.
1169
+
![event-bus-trigger][25]
1170
+
1171
+
The component re-renders anytime the custom "result-added" event is triggered. As a consequence, the counter will be now updated everytime you press the "Add result" button.
1172
+
Remember to remove the listener once you destroy the component.
1173
+
1174
+
Completing that we have also shipped requirement #3.
1170
1175
Refer to **`tag-06-using-vuex`** for what we have done so far.
1171
1176
1172
1177
> "See this? This is my boom stick! It's a 12-gauge, double-barreled Remington. S-mart's top of the line. You can find this in the sporting goods department. [...] It's got a walnut stock, cobalt blue steel and a hair trigger."
1173
1178
>
1174
1179
> <em>(Ashley J. Williams, Army of Darkness)</em>
1175
1180
1176
1181
1182
+
Bonus #1: free Angular components from Angular
1183
+
----
1184
+
A further step in the migration could be rewriting existing Angular components as ES6 modules. You can move them into your webpack build, you can write them in a more concise style, more Vue than Angular, you are maybe learning ES6+ and want to have fun... whatever. Or maybe you are not interested in any restyling (you already write Angular component that way or you prefer to directly migrate the component to Vue). Either is fine.
1185
+
Just in case, you can move for example `angularApp/components/search.js` into `vueApp/src/ngVueBridgeCode/components/Search/index.js`, and rewrite it as:
0 commit comments