Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 186143c

Browse filesBrowse files
committed
Update svelte snippets
1 parent 8412833 commit 186143c
Copy full SHA for 186143c

File tree

Expand file treeCollapse file tree

2 files changed

+51
-105
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+51
-105
lines changed

‎svelte.json

Copy file name to clipboardExpand all lines: svelte.json
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
"body": [
55
"<script lang=\"ts\">",
66
" import { onMount } from 'svelte'",
7-
" import { store } from '@freenit/svelte-base'",
7+
" import { store } from '@freenit/core'",
88
" import { error } from '@freenit/svelte-base/notification'",
99
"",
10-
" const { detail, list } = store().$1",
1110
" let loading = true",
1211
"",
1312
" onMount(async () => {",
14-
" const response = await list.fetch()",
13+
" const response = await store.${1}.fetchAll()",
1514
" if (!response.ok) {",
1615
" error(response.statusText)",
1716
" }",
@@ -20,7 +19,7 @@
2019
"",
2120
" async function fetchPrevious() {",
2221
" loading = true",
23-
" const response = await list.fetch(\\$list.page - 1)",
22+
" const response = await store.${1}.fetchAll(store.${1}.list.page - 1)",
2423
" if (!response.ok) {",
2524
" error(response.statusText)",
2625
" }",
@@ -29,7 +28,7 @@
2928
"",
3029
" async function fetchNext() {",
3130
" loading = true",
32-
" const response = await list.fetch(\\$list.page + 1)",
31+
" const response = await store.${1}.fetchAll(store.${1}.list.page + 1)",
3332
" if (!response.ok) {",
3433
" error(response.statusText)",
3534
" }",

‎typescript.json

Copy file name to clipboardExpand all lines: typescript.json
+47-100Lines changed: 47 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,123 +2,70 @@
22
"store": {
33
"prefix": "freenitstore",
44
"body": [
5-
"import { writable } from 'svelte/store'",
5+
"import { methods, store } from '.'",
66
"",
7-
"class ${1/(.*)/${1:/capitalize}/}ListStore {",
8-
" constructor() {",
9-
" const { set, update } = writable([])",
10-
" this.set = set",
11-
" this.update = update",
12-
" }",
7+
"export default class ${1/(.*)/${1:/capitalize}/}Store {",
8+
" list = \\$state({})",
9+
" detail = \\$state({})",
1310
"",
14-
" async get() {",
15-
" try {",
16-
" const response = await fetch('/api/v1/${1}s')",
17-
" const data = await.response.json()",
18-
" this.set(data)",
19-
" return {",
20-
" ...data,",
21-
" ok: true,",
22-
" }",
23-
" } catch(error) {",
24-
" return {",
25-
" ...error,",
26-
" ok: false",
27-
" }",
28-
" }",
11+
" constructor(prefix) {",
12+
" this.prefix = prefix",
2913
" }",
3014
"",
31-
" async create(${1}Data: Record<string, any>) {",
32-
" try {",
33-
" const response = await fetch(",
34-
" '/api/v1/${1}s', ",
35-
" {method: 'POST', body: ${1}Data},",
36-
" )",
37-
" const data = await.response.json()",
38-
" this.update((store) => [...store, data])",
39-
" return {",
40-
" ...data,",
41-
" ok: true,",
42-
" }",
43-
" } catch(error) {",
44-
" return {",
45-
" ...error,",
46-
" ok: false",
47-
" }",
15+
" fetchAll = async () => {",
16+
" await store.auth.refresh_token()",
17+
" const response = await methods.get(`\\${this.prefix}/${1}s`)",
18+
" if (response.ok) {",
19+
" const data = await response.json()",
20+
" this.list = data",
21+
" return { ...data, ok: true }",
4822
" }",
23+
" return response",
4924
" }",
50-
"}",
5125
"",
52-
"class ${1/(.*)/${1:/capitalize}/}DetailStore {",
53-
" constructor() {",
54-
" const { set, update } = writable({})",
55-
" this.set = set",
56-
" this.update = update",
26+
" create = async (fields: Record<string, any>) => {",
27+
" await store.auth.refresh_token()",
28+
" const response = await methods.post(`\\${this.prefix}/${1}s`, fields)",
29+
" if (response.ok) {",
30+
" const data = await response.json()",
31+
" this.list = data",
32+
" return { ...data, ok: true }",
33+
" }",
34+
" return response",
5735
" }",
5836
"",
59-
" async get(id: Number) {",
60-
" try {",
61-
" const response = await fetch(`/api/v1/${1}s/\\${id}`)",
62-
" const data = await.response.json()",
63-
" this.set(data)",
64-
" return {",
65-
" ...data,",
66-
" ok: true,",
67-
" }",
68-
" } catch(error) {",
69-
" return {",
70-
" ...error,",
71-
" ok: false",
72-
" }",
37+
" fetch = async (id: Number) => {",
38+
" await store.auth.refresh_token()",
39+
" const response = await methods.get(`\\${this.prefix}/${1}s/\\${id}`)",
40+
" if (response.ok) {",
41+
" const data = await response.json()",
42+
" this.detail = data",
43+
" return { ...data, ok: true }",
7344
" }",
45+
" return response",
7446
" }",
7547
"",
76-
" async edit(id: Number, ${1}Data: Record<string, any>) {",
77-
" try {",
78-
" const response = await fetch(",
79-
" `/api/v1/${1}s/\\${id}`,",
80-
" {method: 'PATCH', body: ${1}Data},",
81-
" )",
82-
" const data = await.response.json()",
83-
" this.set(data)",
84-
" return {",
85-
" ...data,",
86-
" ok: true,",
87-
" }",
88-
" } catch(error) {",
89-
" return {",
90-
" ...error,",
91-
" ok: false",
92-
" }",
48+
" edit = async (id: Number, fields: Record<string, any>) => {",
49+
" await store.auth.refresh_token()",
50+
" const response = await methods.patch(`\\${this.prefix}/${1}s/\\${id}`, fields)",
51+
" if (response.ok) {",
52+
" const data = await response.json()",
53+
" this.detail = data",
54+
" return { ...data, ok: true }",
9355
" }",
56+
" return response",
9457
" }",
9558
"",
96-
" async delete(id: Number) {",
97-
" try {",
98-
" const response = await fetch(",
99-
" `/api/v1/${1}s/\\${id}`,",
100-
" {method: 'DELETE'},",
101-
" )",
102-
" const data = await.response.json()",
103-
" return {",
104-
" ...data,",
105-
" ok: true,",
106-
" }",
107-
" } catch(error) {",
108-
" return {",
109-
" ...error,",
110-
" ok: false",
111-
" }",
59+
" destroy = async (id: Number) => {",
60+
" await store.auth.refresh_token()",
61+
" const response = await methods.delete(`\\${this.prefix}/${1}s/\\${id}`)",
62+
" if (response.ok) {",
63+
" const data = await response.json()",
64+
" return { ...data, ok: true }",
11265
" }",
66+
" return response",
11367
" }",
114-
"}",
115-
"",
116-
"const ${1} = {",
117-
" detail: new ${1/(.*)/${1:/capitalize}/}DetailStore(),",
118-
" list: new ${1/(.*)/${1:/capitalize}/}ListStore(),",
119-
"}",
120-
"",
121-
"export default ${1}"
68+
"}"
12269
],
12370
"description": "Freenit Svelte store"
12471
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.