create-qwik 0.0.16 → 0.0.17-0-dev20220303165846

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-qwik",
3
- "version": "0.0.16",
3
+ "version": "0.0.17-0-dev20220303165846",
4
4
  "description": "Interactive CLI and API for generating Qwik projects.",
5
5
  "bin": {
6
6
  "create-qwik": "create-qwik"
@@ -3,7 +3,7 @@
3
3
  "version": "0.0.0",
4
4
  "description": "",
5
5
  "scripts": {
6
- "typecheck": "npx tsc --noEmit",
6
+ "typecheck": "tsc --noEmit",
7
7
  "build": "npm run typecheck && npm run build.client && npm run build.server",
8
8
  "build.client": "vite build",
9
9
  "build.server": "vite build --outDir server/build --ssr src/entry.server.tsx",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "17.0.17",
17
- "@builder.io/qwik": "0.0.16",
17
+ "@builder.io/qwik": "0.0.17-0-dev20220303165846",
18
18
  "typescript": "4.5.5",
19
19
  "vite": "2.8.0"
20
20
  },
@@ -1,11 +1,5 @@
1
1
  import { component$, Host, $ } from '@builder.io/qwik';
2
- import {
3
- clearCompleted,
4
- FilterStates,
5
- getFilteredCount,
6
- Todos,
7
- updateFilter,
8
- } from '../../state/state';
2
+ import { FILTERS, FilterStates, Todos } from '../../state/state';
9
3
 
10
4
  /**
11
5
  * Footer showing items remaining and filtering options
@@ -24,14 +18,16 @@ export const Footer = component$(
24
18
  <li>
25
19
  <a
26
20
  class={{ selected: props.todos.filter == lMode }}
27
- on$:click={() => updateFilter(props.todos, filter)}
21
+ on$:click={() => {
22
+ props.todos.filter = filter;
23
+ }}
28
24
  >
29
25
  {filter[0].toUpperCase() + filter.substr(1)}
30
26
  </a>
31
27
  </li>
32
28
  );
33
29
  }
34
- const remaining = getFilteredCount(props.todos);
30
+ const remaining = props.todos.items.filter(FILTERS.active).length;
35
31
  return (
36
32
  <Host class="footer">
37
33
  {props.todos.items.length > 0 ? (
@@ -46,7 +42,12 @@ export const Footer = component$(
46
42
  ))}
47
43
  </ul>
48
44
  {remaining > 0 ? (
49
- <button class="clear-completed" on$:click={() => clearCompleted(props.todos)}>
45
+ <button
46
+ class="clear-completed"
47
+ on$:click={() => {
48
+ props.todos.items = props.todos.items.filter(FILTERS.active);
49
+ }}
50
+ >
50
51
  Clear completed
51
52
  </button>
52
53
  ) : null}
@@ -1,5 +1,5 @@
1
1
  import { component$, createStore, $, useEvent } from '@builder.io/qwik';
2
- import { addItem, Todos } from '../../state/state';
2
+ import type { Todos } from '../../state/state';
3
3
 
4
4
  /**
5
5
  * Header component which is responsible for providing UI to ender new todo item.
@@ -23,7 +23,10 @@ export const Header = component$(
23
23
  const inputValue = (event.target as HTMLInputElement).value;
24
24
  state.text = inputValue;
25
25
  if (event.key === 'Enter' && inputValue) {
26
- addItem(props.todos, state.text);
26
+ props.todos.items.push({
27
+ completed: false,
28
+ title: state.text,
29
+ });
27
30
  state.text = '';
28
31
  }
29
32
  }}
@@ -7,7 +7,7 @@ import {
7
7
  useEvent,
8
8
  useHostElement,
9
9
  } from '@builder.io/qwik';
10
- import { removeItem, TodoItem, Todos, toggleItem } from '../../state/state';
10
+ import type { TodoItem, Todos } from '../../state/state';
11
11
 
12
12
  /**
13
13
  * Individual items of the component.
@@ -25,7 +25,9 @@ export const Item = component$(
25
25
  class="toggle"
26
26
  type="checkbox"
27
27
  checked={props.item.completed}
28
- on$:click={() => toggleItem(props.todos, props.item)}
28
+ on$:click={() => {
29
+ props.item.completed = !props.item.completed;
30
+ }}
29
31
  />
30
32
  <label
31
33
  on$:dblclick={async () => {
@@ -39,7 +41,13 @@ export const Item = component$(
39
41
  >
40
42
  {props.item.title}
41
43
  </label>
42
- <button class="destroy" on$:click={() => removeItem(props.todos, props.item)}></button>
44
+ <button
45
+ class="destroy"
46
+ on$:click={() => {
47
+ const todoItem = props.item;
48
+ props.todos.items = props.todos.items.filter((i) => i != todoItem);
49
+ }}
50
+ />
43
51
  </div>
44
52
  {state.editing ? (
45
53
  <input
@@ -1,5 +1,5 @@
1
1
  import { component$, Host, $ } from '@builder.io/qwik';
2
- import { getFilteredItems, Todos } from '../../state/state';
2
+ import { FILTERS, Todos } from '../../state/state';
3
3
  import { Item } from '../item/item';
4
4
 
5
5
  /**
@@ -12,7 +12,7 @@ export const Main = component$((props: { todos: Todos }) => {
12
12
  return (
13
13
  <Host class="main">
14
14
  <ul class="todo-list">
15
- {getFilteredItems(props.todos).map((key) => (
15
+ {props.todos.items.filter(FILTERS[props.todos.filter]).map((key) => (
16
16
  <Item item={key} todos={props.todos} />
17
17
  ))}
18
18
  </ul>
@@ -1,4 +1,4 @@
1
- import { component$, $ } from '@builder.io/qwik';
1
+ import { component$, $, createStore } from '@builder.io/qwik';
2
2
  import { Footer } from './components/footer/footer';
3
3
  import { Header } from './components/header/header';
4
4
  import { Main } from './components/main/main';
@@ -7,15 +7,6 @@ import type { Todos } from './state/state';
7
7
  import './base.css';
8
8
  import './index.css';
9
9
 
10
- export const todos: Todos = {
11
- filter: 'all',
12
- items: [
13
- { completed: false, title: 'Read Qwik docs' },
14
- { completed: false, title: 'Build HelloWorld' },
15
- { completed: false, title: 'Profit' },
16
- ],
17
- };
18
-
19
10
  /**
20
11
  * Overall application component.
21
12
  *
@@ -24,6 +15,14 @@ export const todos: Todos = {
24
15
  * download to the client.
25
16
  */
26
17
  export const App = component$(() => {
18
+ const todos = createStore<Todos>({
19
+ filter: 'all',
20
+ items: [
21
+ { completed: false, title: 'Read Qwik docs' },
22
+ { completed: false, title: 'Build HelloWorld' },
23
+ { completed: false, title: 'Profit' },
24
+ ],
25
+ });
27
26
  return $(() => {
28
27
  return (
29
28
  <section class="todoapp">
@@ -12,51 +12,12 @@ export interface Todos {
12
12
  items: TodoItem[];
13
13
  }
14
14
 
15
- ////////////////////////////////////////////////////////////////////////
16
- // Todo Application State Mutation Functions
17
- ////////////////////////////////////////////////////////////////////////
18
-
19
- export function addItem(todos: Todos, text: string) {
20
- todos.items.push({ completed: false, title: text });
21
- updateFilter(todos);
22
- }
23
-
24
- export function removeItem(todos: Todos, todoItem: TodoItem) {
25
- todos.items = todos.items.filter((i) => i != todoItem);
26
- updateFilter(todos);
27
- }
28
- export function toggleItem(todos: Todos, todoItem: TodoItem) {
29
- todoItem.completed = !todoItem.completed;
30
- updateFilter(todos);
31
- }
32
-
33
- export function clearCompleted(todos: Todos) {
34
- todos.items = todos.items.filter(FILTERS.active);
35
- updateFilter(todos);
36
- }
37
-
38
- ////////////////////////////////////////////////////////////////////////
39
- // Todo Application State Filter Functions
40
- ////////////////////////////////////////////////////////////////////////
41
-
42
15
  export type FilterStates = 'all' | 'active' | 'completed';
16
+
43
17
  export const FilterStates: FilterStates[] = ['all', 'active', 'completed'];
18
+
44
19
  export const FILTERS = {
45
20
  all: () => true,
46
21
  active: (i: TodoItem) => i.completed == false,
47
22
  completed: (i: TodoItem) => i.completed == true,
48
23
  };
49
-
50
- export function updateFilter(todos: Todos, filter?: FilterStates) {
51
- if (filter) {
52
- todos.filter = filter.toLowerCase() as any;
53
- }
54
- }
55
-
56
- export function getFilteredItems(todos: Todos): TodoItem[] {
57
- return todos.items.filter(FILTERS[todos.filter]);
58
- }
59
-
60
- export function getFilteredCount(todos: Todos) {
61
- return getFilteredItems(todos).filter(FILTERS.active).length;
62
- }