STORE_NAME variable created
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
<script>
|
<script>
|
||||||
import { fade } from "svelte/transition";
|
import { fade } from "svelte/transition";
|
||||||
import { chores } from "./stores/twiliostore";
|
import { chores, STORE_NAME } from "./stores/twiliostore";
|
||||||
|
|
||||||
let newChore = "";
|
let newChore = "";
|
||||||
|
|
||||||
const createChore = () => {
|
const createChore = () => {
|
||||||
pushItem("chores", { chore: newChore });
|
pushItem(STORE_NAME, { chore: newChore });
|
||||||
newChore = "";
|
newChore = "";
|
||||||
};
|
};
|
||||||
const deleteChore = (index) => removeItem("chores", index);
|
const deleteChore = (index) => removeItem(STORE_NAME, index);
|
||||||
const updateChore = (index, newValue) => chores.update(index, newValue);
|
const updateChore = (index, newValue) => chores.update(index, newValue);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export const STORE_NAME = 'chores';
|
||||||
|
|
||||||
function createTwilioStore() {
|
function createTwilioStore() {
|
||||||
const { subscribe, update, set } = writable([]);
|
const { subscribe, update, set } = writable([]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { chores } from "./stores/twiliostore";
|
import { chores, STORE_NAME } from "./stores/twiliostore";
|
||||||
|
|
||||||
const storeName = 'chores';
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
let syncClient;
|
let syncClient;
|
||||||
@@ -60,10 +58,10 @@ const storeName = 'chores';
|
|||||||
};
|
};
|
||||||
|
|
||||||
// as soon as Twilio is working, we write on the store
|
// as soon as Twilio is working, we write on the store
|
||||||
getItems(storeName).then((items) => chores.getItems(items));
|
getItems(STORE_NAME).then((items) => chores.getItems(items));
|
||||||
|
|
||||||
// and we declare the listeners to update the store
|
// and we declare the listeners to update the store
|
||||||
getList(storeName).then((choreList) => {
|
getList(STORE_NAME).then((choreList) => {
|
||||||
choreList.on("itemAdded", (item) => chores.itemAdded(item));
|
choreList.on("itemAdded", (item) => chores.itemAdded(item));
|
||||||
choreList.on("itemRemoved", (args) => chores.itemRemoved(args));
|
choreList.on("itemRemoved", (args) => chores.itemRemoved(args));
|
||||||
choreList.on("itemUpdated", (args) => chores.itemUpdated(args));
|
choreList.on("itemUpdated", (args) => chores.itemUpdated(args));
|
||||||
|
|||||||
Reference in New Issue
Block a user