Getting Started with Nuxt + Composition API + TypeScript
In this article, it assumes you have the basic knowledge and understanding of:VueNuxt jsTypeScriptVue 3: Composition APIUnsupported embedInstallationOpen your terminal and run this command npx create-nuxt-app nuxt-ts-composition-api make sure to select TypeScript, and $axios during the selection process. Iโm not gonna go through the installation process but you can refer to the official documentation https://nuxtjs.org/docs/2.x/get-started/installation Then install @nuxtjs/composition-api mod...
Generating Fake Data in Flutter using the Factory Pattern for Unit Testing
IntroductionIn this article we will learn how we can seamlessly generate fake data in Flutter that we can use with-in our test suites, or just for some placeholder data in our app when the backend is not completely setup yet or any other scenario that we just need a fake data in general. You will also learn how to create a Flutter package and use that package with-in your application, it can be used both in lib and test folder. And lastly you will learn how to setup a basic monorepo for your ...
Building a simple Grocery App in Flutter with Supabase
Unsupported embedIntroductionIn this article I will show you how you can build an application using Flutter with Supabase as a backend. Supabase is a Firebase alternative which uses Postgres, so that's something different and that's even amazing. Postgres is also a relational database which is also open source and a powerful tool. We will learn and build a simple grocery application using Flutter with Supabase. I am not going to go over setting up Flutter step by step since how I bu...

Subscribe to Carlo Miguel Dy
Getting Started with Nuxt + Composition API + TypeScript
In this article, it assumes you have the basic knowledge and understanding of:VueNuxt jsTypeScriptVue 3: Composition APIUnsupported embedInstallationOpen your terminal and run this command npx create-nuxt-app nuxt-ts-composition-api make sure to select TypeScript, and $axios during the selection process. Iโm not gonna go through the installation process but you can refer to the official documentation https://nuxtjs.org/docs/2.x/get-started/installation Then install @nuxtjs/composition-api mod...
Generating Fake Data in Flutter using the Factory Pattern for Unit Testing
IntroductionIn this article we will learn how we can seamlessly generate fake data in Flutter that we can use with-in our test suites, or just for some placeholder data in our app when the backend is not completely setup yet or any other scenario that we just need a fake data in general. You will also learn how to create a Flutter package and use that package with-in your application, it can be used both in lib and test folder. And lastly you will learn how to setup a basic monorepo for your ...
Building a simple Grocery App in Flutter with Supabase
Unsupported embedIntroductionIn this article I will show you how you can build an application using Flutter with Supabase as a backend. Supabase is a Firebase alternative which uses Postgres, so that's something different and that's even amazing. Postgres is also a relational database which is also open source and a powerful tool. We will learn and build a simple grocery application using Flutter with Supabase. I am not going to go over setting up Flutter step by step since how I bu...
Share Dialog
Share Dialog
In this article we will be learning how to use Vue's provide and inject.
Open your terminal and create a fresh Vue project,\
$ vue create vue-3-dependency-injection
Then open the scaffolded project by the CLI in your IDE.\
$ cd vue-3-dependency-injection && code .
As an example, let's say our client wants to have the user's name in many places in our application. But there are many ways to do that, but the team decided to only go with provide() so it can supply data to components.
Note: The example scenario may not be so ideal but just to demo how provide() and inject() works\
<template>
<AppFirstChild />
<AppSecondChild />
<AppThirdChild />
</template>
<script>
import { defineComponent, provide } from "@vue/runtime-core";
import AppFirstChild from "./components/AppFirstChild.vue";
import AppSecondChild from "./components/AppSecondChild.vue";
import AppThirdChild from "./components/AppThirdChild.vue";
export default defineComponent({
name: "App",
components: {
AppFirstChild,
AppSecondChild,
AppThirdChild,
},
setup() {
provide("user", "Carlo Miguel Dy");
},
});
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
But we can just use props instead? We can definitely pass down props from Parent to child component and this child component passes down this prop to its other child components, and when that child component also has its own child components that needs the data from the root component you pass down props as well.
Actually this is a problem and things might not be that consistent across our application. So the solution to that problem is to use dependency injection with provide() and have all the nested child components use inject() to get the provided data.
The one way we can use or get the value from provide() is to use inject(). We'll import that also from @vue/runtime-core. Now let us inject the provided data from our Parent component.
For component AppFirstChild\
<template>
<h1>{{ user }}</h1>
<AppFirstChildChild />
</template>
<script>
import { defineComponent, inject } from "vue";
import AppFirstChildChild from "./AppFirstChildChild.vue";
export default defineComponent({
components: {
AppFirstChildChild,
},
setup() {
const user = inject("user");
return {
user,
};
},
});
</script>
As you see AppFirstChild component also has a child component. We can also use inject() to get the data provided from the root Parent component easily.
for component AppFirstChildChild\
<template>
<h1>AppFirstChildChild: {{ user }}</h1>
</template>
<script>
import { defineComponent, inject } from "vue";
export default defineComponent({
setup() {
const user = inject("user");
return {
user,
};
},
});
</script>
We are not only limited to provide values as string, we can pass down any type of data. It can be an array, a number, or an object.
So let us provide another data with emojis\
export default defineComponent({
name: "App",
components: {
AppFirstChild,
AppSecondChild,
AppThirdChild,
},
setup() {
provide("user", "Carlo Miguel Dy");
provide("emojis", {
fire: "๐ฅ",
star: "โญ",
pizza: "๐",
});
},
});
Our client is happy with the functionality that we created, cheers!
When we want to be consistent in passing down values to other child components across our entire application, we should use provide() and inject() instead as it saves us the time and all the frustrations when just using props.
Thanks for taking the time to read, hope you had a wonderful weekend!
In this article we will be learning how to use Vue's provide and inject.
Open your terminal and create a fresh Vue project,\
$ vue create vue-3-dependency-injection
Then open the scaffolded project by the CLI in your IDE.\
$ cd vue-3-dependency-injection && code .
As an example, let's say our client wants to have the user's name in many places in our application. But there are many ways to do that, but the team decided to only go with provide() so it can supply data to components.
Note: The example scenario may not be so ideal but just to demo how provide() and inject() works\
<template>
<AppFirstChild />
<AppSecondChild />
<AppThirdChild />
</template>
<script>
import { defineComponent, provide } from "@vue/runtime-core";
import AppFirstChild from "./components/AppFirstChild.vue";
import AppSecondChild from "./components/AppSecondChild.vue";
import AppThirdChild from "./components/AppThirdChild.vue";
export default defineComponent({
name: "App",
components: {
AppFirstChild,
AppSecondChild,
AppThirdChild,
},
setup() {
provide("user", "Carlo Miguel Dy");
},
});
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
But we can just use props instead? We can definitely pass down props from Parent to child component and this child component passes down this prop to its other child components, and when that child component also has its own child components that needs the data from the root component you pass down props as well.
Actually this is a problem and things might not be that consistent across our application. So the solution to that problem is to use dependency injection with provide() and have all the nested child components use inject() to get the provided data.
The one way we can use or get the value from provide() is to use inject(). We'll import that also from @vue/runtime-core. Now let us inject the provided data from our Parent component.
For component AppFirstChild\
<template>
<h1>{{ user }}</h1>
<AppFirstChildChild />
</template>
<script>
import { defineComponent, inject } from "vue";
import AppFirstChildChild from "./AppFirstChildChild.vue";
export default defineComponent({
components: {
AppFirstChildChild,
},
setup() {
const user = inject("user");
return {
user,
};
},
});
</script>
As you see AppFirstChild component also has a child component. We can also use inject() to get the data provided from the root Parent component easily.
for component AppFirstChildChild\
<template>
<h1>AppFirstChildChild: {{ user }}</h1>
</template>
<script>
import { defineComponent, inject } from "vue";
export default defineComponent({
setup() {
const user = inject("user");
return {
user,
};
},
});
</script>
We are not only limited to provide values as string, we can pass down any type of data. It can be an array, a number, or an object.
So let us provide another data with emojis\
export default defineComponent({
name: "App",
components: {
AppFirstChild,
AppSecondChild,
AppThirdChild,
},
setup() {
provide("user", "Carlo Miguel Dy");
provide("emojis", {
fire: "๐ฅ",
star: "โญ",
pizza: "๐",
});
},
});
Our client is happy with the functionality that we created, cheers!
When we want to be consistent in passing down values to other child components across our entire application, we should use provide() and inject() instead as it saves us the time and all the frustrations when just using props.
Thanks for taking the time to read, hope you had a wonderful weekend!
<100 subscribers
<100 subscribers
No activity yet