Skip to content
Snippets Groups Projects
Commit 8ce454c1 authored by insert's avatar insert
Browse files

Use Array.fill instead to allocate on start, also updated README

parent 799d52b5
Branches
No related merge requests found
...@@ -4,13 +4,18 @@ ...@@ -4,13 +4,18 @@
This library allows you to create Google Contacts style dynamic lists, it is built upon Vue.js hence is easy to integrate into existing websites with or without Vue. This library allows you to create Google Contacts style dynamic lists, it is built upon Vue.js hence is easy to integrate into existing websites with or without Vue.
### Demo - [GitLab repository](https://gitlab.insrt.uk/insert/vue-dynamic-list)
--- - [NPM package](https://www.npmjs.com/package/vue-dynamic-list)
![demo](https://owo.insrt.uk/b9d1435e.mp4) - [unpkg CDN link](https://unpkg.com/vue-dynamic-list@1.0.1/index.js)
### Usage ### Usage
--- ---
Include the library:
```html
<script src="https://unpkg.com/vue-dynamic-list@1.0.1/index.js"></script>
```
In your Vue.js application: In your Vue.js application:
```html ```html
<dynamic-list ref="myList"> <dynamic-list ref="myList">
...@@ -25,6 +30,7 @@ In your Vue.js application: ...@@ -25,6 +30,7 @@ In your Vue.js application:
Using the library: Using the library:
```js ```js
// create your Vue app, with dynamic-list nested in it
const app = new Vue({ const app = new Vue({
el: '#app' el: '#app'
}); });
...@@ -45,4 +51,17 @@ new vDynamicList(app, { ...@@ -45,4 +51,17 @@ new vDynamicList(app, {
// choose a suitable limit for each section // choose a suitable limit for each section
limit: 100 limit: 100
}); });
``` ```
\ No newline at end of file
### Comparison
---
> Vue Dynamic List on the left alongside Google Contacts
![Comparison between Google Contacts and Vue Dynamic List](https://owo.insrt.uk/500a5b64.png)
### Demo
---
![Demo Video](https://owo.insrt.uk/b9d1435e.mp4)
> Not embedding? [(Direct Link)](https://owo.insrt.uk/b9d1435e.mp4)
\ No newline at end of file
...@@ -6,12 +6,11 @@ class _vDynamicUpdateCycle { ...@@ -6,12 +6,11 @@ class _vDynamicUpdateCycle {
this.total = Math.ceil(total / limit); this.total = Math.ceil(total / limit);
this.limit = limit; this.limit = limit;
this.states = []; this.states = Array(this.total).fill(0);
this.loadQueue = []; this.loadQueue = [];
this.canUpdate = true; this.canUpdate = true;
for (let i=0;i<this.total;i++) { for (let i=0;i<this.total;i++) {
this.states.push({loaded: false, loading: false});
this.component.sections.push(false); this.component.sections.push(false);
} }
...@@ -25,15 +24,13 @@ class _vDynamicUpdateCycle { ...@@ -25,15 +24,13 @@ class _vDynamicUpdateCycle {
}); });
} }
populate(x, e = false) { populate(x, e = false) {
let y = []; return Array(x).fill(e);
for (let i=0;i<x;i++) y.push(e);
return y;
} }
updateElm(i, v) { updateElm(i, v) {
return new Promise(resolve => { return new Promise(resolve => {
this.load(i, this.limit).then(data => { this.load(i, this.limit).then(data => {
this.component.sections.splice(i, 1, data); this.component.sections.splice(i, 1, data);
this.states[i].loaded = true; this.states[i] = 2;
resolve(); resolve();
}); });
}); });
...@@ -49,16 +46,13 @@ class _vDynamicUpdateCycle { ...@@ -49,16 +46,13 @@ class _vDynamicUpdateCycle {
let entries = $('.section'); let entries = $('.section');
for (let i=0;i<entries.length;i++) { for (let i=0;i<entries.length;i++) {
let v = entries[i]; let v = entries[i];
if (!this.states[i].loading) { if (this.visible(entries[i])) {
if (this.visible(entries[i])) { switch (this.states[i]) {
this.component.sections.splice(i, 1, this.populate(this.limit)); case 0:
this.states[i].loading = true; this.component.sections.splice(i, 1, this.populate(this.limit));
} this.states[i]++;
} case 1:
if (!this.states[i].loaded) { if (this.loadQueue.indexOf([i, v] == -1)) this.loadQueue.push([i, v]);
if (this.visible(entries[i])) {
this.component.sections.splice(i, 1, this.populate(this.limit));
if (this.loadQueue.indexOf([i, v] == -1)) this.loadQueue.push([i, v]);
} }
} }
}; };
......
{ {
"name": "vue-dynamic-list", "name": "vue-dynamic-list",
"version": "1.0.0", "version": "1.0.1",
"description": "Simple fixed size dynamically loading lists in Vue.js", "description": "Simple fixed size dynamically loading lists in Vue.js",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment