Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit 4ecb128

Browse files
committed
initial commit
0 parents  commit 4ecb128

15 files changed

+2165
-0
lines changed

.eslintrc.cjs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// eslint-disable-next-line no-undef
2+
module.exports = {
3+
root: true,
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:prettier/recommended',
7+
'plugin:@typescript-eslint/eslint-recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
8+
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
9+
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
10+
],
11+
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
12+
env: {
13+
browser: true,
14+
es6: true,
15+
jest: true,
16+
node: true,
17+
},
18+
parserOptions: {
19+
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
20+
sourceType: 'module', // Allows for the use of imports
21+
ecmaFeatures: {
22+
jsx: true, // Allows for the parsing of JSX
23+
arrowFunctions: true,
24+
},
25+
// Next two lines enable deeper TS type checking
26+
// https://typescript-eslint.io/docs/linting/typed-linting/
27+
tsconfigRootDir: __dirname,
28+
},
29+
plugins: ['@typescript-eslint', 'prettier'],
30+
settings: {
31+
'import/resolver': {
32+
node: {
33+
extensions: ['.js', '.svelte', '.ts', '.tsx'],
34+
paths: ['./src'],
35+
},
36+
},
37+
},
38+
rules: {
39+
// Existing rules
40+
'comma-dangle': 'off', // https://eslint.org/docs/rules/comma-dangle
41+
'function-paren-newline': 'off', // https://eslint.org/docs/rules/function-paren-newline
42+
'global-require': 'off', // https://eslint.org/docs/rules/global-require
43+
'import/no-dynamic-require': 'off', // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
44+
'class-methods-use-this': 'off',
45+
'@typescript-eslint/no-unused-vars': [
46+
'error',
47+
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
48+
],
49+
'import/prefer-default-export': 'off',
50+
'@typescript-eslint/explicit-function-return-type': 'off',
51+
'@typescript-eslint/no-var-requires': 'off',
52+
'@typescript-eslint/ban-ts-comment': 'off',
53+
'no-console': ['error', { allow: ['error', 'warn'] }],
54+
'padding-line-between-statements': [
55+
'error',
56+
{
57+
blankLine: 'always',
58+
next: 'return',
59+
prev: '*',
60+
},
61+
{
62+
blankLine: 'always',
63+
next: 'export',
64+
prev: '*',
65+
},
66+
{
67+
blankLine: 'always',
68+
next: 'multiline-block-like',
69+
prev: '*',
70+
},
71+
{
72+
blankLine: 'always',
73+
next: '*',
74+
prev: 'multiline-block-like',
75+
},
76+
{
77+
blankLine: 'any',
78+
next: 'export',
79+
prev: 'export',
80+
},
81+
],
82+
'@typescript-eslint/explicit-member-accessibility': 'error',
83+
eqeqeq: 'error',
84+
'no-unused-expressions': [
85+
'error',
86+
{ allowShortCircuit: true, allowTaggedTemplates: true },
87+
],
88+
// This has a bug, so we use typescripts version
89+
'no-shadow': 'off',
90+
'@typescript-eslint/no-shadow': ['error'],
91+
'@typescript-eslint/no-non-null-assertion': 'off',
92+
'no-eval': 'error',
93+
'no-implied-eval': 'error',
94+
'@typescript-eslint/member-ordering': 'error',
95+
},
96+
};

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
dist/*
14+
*.local
15+
16+
# Editor directories and files
17+
.vscode/*
18+
!.vscode/extensions.json
19+
.idea
20+
.DS_Store
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?

.prettierrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"semi": true,
3+
"printWidth": 80,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"bracketSpacing": true,
7+
"useTabs": false,
8+
"arrowParens": "avoid",
9+
"jsxSingleQuote": true,
10+
"trailingComma": "all",
11+
"jsdocParser": true
12+
}

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# @tomic/svelte
2+
3+
An implementation of Atomic Data for [Svelte](https://svelte.dev/).
4+
This library is still at an early stage and the API is subject to change.
5+
6+
## Quick Examples
7+
8+
### Getting a resource and displaying one of its properties
9+
```html
10+
<script lang="ts">
11+
import { getResource, getValue } from '@tomic/svelte';
12+
import { urls } from '@tomic/lib';
13+
14+
const resource = getResource('https://example.com/');
15+
const name = getValue<string>(resource, urls.properties.name);
16+
</script>
17+
18+
<h1>{$name}</h1>
19+
```
20+
21+
### Changing the value of a property with an input field
22+
```html
23+
<script lang="ts">
24+
import { getResource, getValue, setValue } from '@tomic/svelte';
25+
import { urls } from '@tomic/lib';
26+
27+
const resource = getResource('https://example.com/');
28+
const name = getValue<string>(resource, urls.properties.name);
29+
</script>
30+
31+
<input bind:value={$name} />
32+
```
33+
34+
## Getting started
35+
36+
Install the library with your prefered package manager: <br />
37+
```
38+
npm install -S @tomic/svelte @tomic/lib
39+
```
40+
```
41+
yarn add @tomic/svelte @tomic/lib
42+
```
43+
```
44+
pnpm add @tomic/svelte @tomic/lib
45+
```
46+
47+
Initialise the store
48+
```html
49+
// App.svelte
50+
51+
<script lang="ts">
52+
import { initStore } from '@tomic/svelte';
53+
import { Store } from '@tomic/lib';
54+
55+
onMount(() => {
56+
// This is where you configure your atomic data store.
57+
const store = new Store();
58+
initStore(store);
59+
})
60+
</script>
61+
62+
// do sveltey things
63+
```
64+
65+
You can now acces this store from any component in your app with the store store.
66+
```html
67+
// Some random component.svelte
68+
69+
<script lang="ts">
70+
import { store } from '@tomic/svelte';
71+
72+
const resource = $store.getResourceLoading('https://atomicdata.dev/documents/tgzamh5hk2t');
73+
</script>
74+
```
75+
76+
However this resource does not update when some of its data changes somewhere else in your app.
77+
That's where the `getResource` and `getValue` functions come in handy.
78+
79+
To get a value and display it in your component we first retrieve (or create) a resource from the store with `getResource` and then get it's value with `getValue`.
80+
81+
```html
82+
// Some random component.svelte
83+
84+
<script lang="ts">
85+
import { getResource, getValue } from '@tomic/svelte';
86+
import { urls } from '@tomic/lib';
87+
88+
const resource = getResource('https://example.com/');
89+
const name = getValue<string>(resource, urls.properties.name);
90+
</script>
91+
92+
<main>
93+
<h1>{$name}</h1>
94+
...
95+
```
96+
97+
Updating values of a resource is super simple, just do what you would normaly do with a writable svelte store:
98+
```ts
99+
const value = getValue<string>(resource, urls.properties.name);
100+
101+
$value = "New Value";
102+
```
103+
104+
The value now updates and changes will permeate through the store.

package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@tomic/svelte",
3+
"description": "Atomic Data Svelte library",
4+
"author": "Polle Pas",
5+
"private": false,
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"version": "0.0.0",
10+
"type": "module",
11+
"exports": {
12+
".": {
13+
"import": "./dist/main.es.js",
14+
"require": "./dist/main.cjs.js"
15+
}
16+
},
17+
"main": "./dist/main.cjs.js",
18+
"module": "./dist/main.es.js",
19+
"typings": "./dist/main.d.ts",
20+
"files": [
21+
"dist"
22+
],
23+
"scripts": {
24+
"dev": "vite",
25+
"build": "tsc && vite build",
26+
"build:watch": "tsc && vite build --watch",
27+
"lint": "eslint ./src --ext .js,.svelte,.ts,.tsx",
28+
"lint-fix": "eslint ./src --ext .js,.svelte,.ts,.tsx --fix",
29+
"test": "vitest",
30+
"coverage": "vitest --coverage"
31+
},
32+
"devDependencies": {
33+
"@rollup/plugin-typescript": "^10.0.1",
34+
"@types/node": "^18.11.17",
35+
"@typescript-eslint/eslint-plugin": "^5.47.0",
36+
"@typescript-eslint/parser": "^5.47.0",
37+
"eslint-config-prettier": "^8.5.0",
38+
"eslint-plugin-prettier": "^4.2.1",
39+
"prettier": "^2.8.1",
40+
"rollup-plugin-typescript-paths": "^1.4.0",
41+
"tslib": "^2.4.1",
42+
"typescript": "^4.9.3",
43+
"vite": "^4.0.0",
44+
"vitest": "^0.26.1"
45+
},
46+
"packageManager": "pnpm@7.13.3",
47+
"dependencies": {
48+
"@tomic/lib": "^0.34.0",
49+
"eslint": "^8.30.0",
50+
"svelte": "^3.55.0"
51+
}
52+
}

0 commit comments

Comments
 (0)