473,414 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,414 developers and data experts.

Vandf component communication method one: data sharing

### Vandf component communication method one: data sharing

​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method is achieved through upper level data transmission, input from the Input component, click outside the box to trigger the change event, and then automatically update the data of the TextArea component, and vice versa. Just look at the example. Document reference [vandf - npm (npmjs.com)](https://www.npmjs.com/package/vandf)

#### 1.Defining Input Components

```javascript
class Input extends Van {
constructor(id){
super(id)
this.tag('input')//input
.view(InputView)//View model for binding components
}
}
```

### 2.定义TextArea组件

```javascript
class TextArea extends Van {
constructor(id){
super(id)
this.tag('textarea')//textarea
.view(InputView)//Bind the view model of components, and reuse the view model due to consistent component behavior.
}
}
```

### 3.Define View Model

```javascript
class InputView {
create(node,model){
node.on("change", e=>{
model.setValue(node.index, node.text())//Update model data
node.parent().update()//To update two subcomponents, refresh the parent component
}, true)//Pass in true and register native events
}
render(node,model){
node.text(d=>d)
}
}
```

### 4.Define user data model

```javascript
class UserModel {
supply(data){
this.data = data.value;//Receive data transmitted by upper level components and extract the data.
return this.data;
}

getValue(index){
return this.data[index]
}

setValue(index, value){
this.data[index] = value
}
}
```

### 5.Building applications using components

```javascript
import { Van } from "vandf"
let app = Van.new('app').supply({value:["Happly"]})//provide data
Input.new('input', app.id).model(UserModel)//Registration Model
TextArea.new('textarea', app.id).model(UserModel)//Reuse user model due to two consistent behaviors
app.attach(document.querySelector("#app"))
```

#### 6.Summarize

​ From this example, the following conclusions can be drawn:
-The Vandf framework enables layer by layer transmission of data, making it extremely easy to achieve data sharing between sub components.
-The Vandf model deconstructs component definitions, view model definitions, and user model definitions, improving their reusability.
Jan 20 '24 #1
0 20566

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: FRITS VAN HEES | last post by:
Is there a way to find out in a data sharing environment in which member one is executing ?
0
by: Kenny G | last post by:
Hello, Got a small problem: I built a small table and used the following on my laptop this morning. This code compiled and worked fine on my laptop but when I compiled the first Sub on my...
2
by: bradleyp | last post by:
Hi all, Hopefully somebody can help. In Access 2002-SP2, I receive an error from the VB Editor if I try to compile the following code (see below). The error is as follows: Compile Error:...
1
by: almeister9 | last post by:
I am hoping someone can help me as I've done this sort of thing before with no problems. I am using Access 2003 SP2 on WinXP prof SP2 I have an unbound form (single form view) with 18 unbound text...
1
by: Khalil ur Rehma | last post by:
Error "Method or Data Member not found" here is my code if any one may solve my problem. Dim conDataConnection As Connection Dim strSQL As String Dim lstSel As ListItem Set...
15
by: Elizabeth Mitte | last post by:
Hello, Before I ask my question, I want to say how good this forum is and how much help it has been to a complete novice. At this moment in time I am having trouble creating VBA syntax (I think...
1
by: markjoseph | last post by:
hI, would you like to help my problem, I'm a new programmer and I had encounter an error in my new program. Compile Error : Method or data member not found I'm using vb6 and my database is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.