Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: joist-framework/joist
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: joist-framework/joist
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.1
Choose a head ref
  • 19 commits
  • 21 files changed
  • 2 contributors

Commits on Aug 1, 2022

  1. Cleanup (#754)

    * rename upgradable mixin class
    
    * remove lit from example
    
    * fully independent todo example
    
    * update lockfile
    
    * update integration example
    
    * remove unused symbol for todo service
    Danny Blue authored Aug 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    483d7bf View commit details
  2. Update README.md

    Danny Blue authored Aug 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a650ff0 View commit details

Commits on Aug 4, 2022

  1. Cleanup (#755)

    * rename upgradable mixin class
    
    * remove lit from example
    
    * fully independent todo example
    
    * update lockfile
    
    * update integration example
    
    * remove unused symbol for todo service
    
    * 2.0
    
    * update docs for 2.0
    
    * update README.md
    
    * v2.0.0
    Danny Blue authored Aug 4, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    stefanprodan Stefan Prodan
    Copy the full SHA
    7c9327f View commit details
  2. Update README.md

    Danny Blue authored Aug 4, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    stefanprodan Stefan Prodan
    Copy the full SHA
    5dab26a View commit details

Commits on Aug 6, 2022

  1. chore(deps): update dependency @web/test-runner to v0.14.0 (#757)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 6, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4990ebf View commit details

Commits on Aug 8, 2022

  1. chore(deps): update dependency lerna to v5.4.0 (#759)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 8, 2022
    Copy the full SHA
    a5d81a4 View commit details

Commits on Aug 9, 2022

  1. chore(deps): update dependency vite to v3.0.5 (#760)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 9, 2022
    Copy the full SHA
    bb11893 View commit details

Commits on Aug 11, 2022

  1. chore(deps): update dependency vite to v3.0.6 (#761)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 11, 2022
    Copy the full SHA
    b3582d2 View commit details

Commits on Aug 12, 2022

  1. chore(deps): update dependency lit to v2.3.0 (#762)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 12, 2022
    Copy the full SHA
    c821df5 View commit details
  2. chore(deps): update dependency vite to v3.0.7 (#765)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 12, 2022
    Copy the full SHA
    3e93402 View commit details
  3. chore(deps): update dependency lerna to v5.4.1 (#764)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 12, 2022
    Copy the full SHA
    afdcd17 View commit details

Commits on Aug 14, 2022

  1. chore(deps): update dependency lerna to v5.4.2 (#767)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 14, 2022
    Copy the full SHA
    27e3e08 View commit details

Commits on Aug 16, 2022

  1. chore(deps): update dependency vite to v3.0.8 (#768)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 16, 2022
    Copy the full SHA
    0b48c29 View commit details

Commits on Aug 17, 2022

  1. chore(deps): update dependency lerna to v5.4.3 (#769)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 17, 2022
    Copy the full SHA
    abd3d0a View commit details
  2. chore(deps): update dependency @microsoft/fast-element to v1.10.5 (#770)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 17, 2022
    Copy the full SHA
    6df3c17 View commit details

Commits on Aug 19, 2022

  1. chore(deps): update dependency lit to v2.3.1 (#771)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 19, 2022
    Copy the full SHA
    30bdfba View commit details
  2. chore(deps): update dependency vite to v3.0.9 (#772)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 19, 2022
    Copy the full SHA
    c4c084d View commit details

Commits on Aug 20, 2022

  1. fix export map for styled

    deebloo committed Aug 20, 2022
    Copy the full SHA
    b822d2e View commit details
  2. v2.0.1

    deebloo committed Aug 20, 2022
    Copy the full SHA
    79cfc15 View commit details
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,4 @@ This toolkit is here to help provide just the functionality you need and nothing
| [@joist/query](packages/query) | query custom elements and assign to property. |
| [@joist/styled](packages/styled) | Apply styles to shadow dom. (Constructable stylesheets with fallback) |

NOTE: This branch contains the next available version (2.0.0) and is available under the "canary" tag. The API is solidfying and should be stable shortly.

[Try it out with Vite and Stackblitz!](https://stackblitz.com/edit/joist-starter-app-vite)
[Try it out with Vite and Stackblitz!](https://stackblitz.com/github/joist-framework/starter-app-vite?file=index.html)
44 changes: 43 additions & 1 deletion integration/own/index.html
Original file line number Diff line number Diff line change
@@ -48,6 +48,46 @@
position: relative;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}

todo-form:not(:defined) {
border-bottom: solid 1px rgb(243, 243, 243);
background: #fff;
display: block;
height: 65px;
}

todo-list:not(:defined) {
border-bottom: solid 1px rgb(243, 243, 243);
background: #fff;
display: flex;
align-items: center;
justify-content: center;
position: relative;
padding: 2rem 0;
}

#loader {
content: '';
box-sizing: border-box;
width: 50px;
height: 50px;
border-radius: 50%;
border-top: 2px solid #07d;
border-right: 2px solid transparent;
animation: spinner 0.6s linear infinite;
}

todo-list-footer:not(:defined) {
background: #fff;
display: block;
height: 50px;
}

@keyframes spinner {
to {
transform: rotate(360deg);
}
}
</style>

<header>
@@ -57,7 +97,9 @@ <h1>todos</h1>
<local-storage-ctx>
<todo-form></todo-form>

<todo-list></todo-list>
<todo-list>
<div id="loader" slot="loading"></div>
</todo-list>

<todo-list-footer></todo-list-footer>

15 changes: 10 additions & 5 deletions integration/own/src/services/storage.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { service } from '@joist/di';

export interface Storage {
loadJSON<T>(key: string): Promise<T | undefined>;
saveJSON<T>(key: string, val: T): Promise<boolean>;
}

@service
export class AppStorage {
export class AppStorage implements Storage {
data: Record<string, any> = {};

loadJSON<T>(key: string): T | undefined {
return this.data[key];
loadJSON<T>(key: string): Promise<T | undefined> {
return Promise.resolve(this.data[key] as T);
}

saveJSON<T extends object>(key: string, val: T): boolean {
saveJSON<T>(key: string, val: T): Promise<boolean> {
this.data[key] = val;

return true;
return Promise.resolve(true);
}
}
64 changes: 38 additions & 26 deletions integration/own/src/services/todo.service.ts
Original file line number Diff line number Diff line change
@@ -7,23 +7,16 @@ export const enum TodoStatus {
Complete = 'complete',
}

const todoSecret = Symbol();

export class Todo {
static create(name: string, status: TodoStatus) {
return new Todo(crypto.randomUUID(), name, status, todoSecret);
return new Todo('todo--' + crypto.randomUUID(), name, status);
}

constructor(
public readonly id: string,
public readonly name: string,
public readonly status: TodoStatus,
secret: Symbol
) {
if (secret !== todoSecret) {
throw new Error('use Todo.create');
}
}
public readonly status: TodoStatus
) {}
}

export class TodoUpdatedEvent extends Event {
@@ -48,50 +41,69 @@ export class TodoRemovedEvent extends Event {
export class TodoService extends EventTarget {
static inject = [AppStorage];

todos: Todo[] = [];

private store: AppStorage;
private todos: Todo[] = [];
private store = this.getStore();
private initialized = false;

constructor(store: Injected<AppStorage>) {
constructor(private getStore: Injected<AppStorage>) {
super();
}

this.store = store();
getTodos(): Promise<Todo[]> {
if (this.initialized) {
return Promise.resolve(this.todos);
}

const stored = this.store.loadJSON<Todo[]>('joist_todo');
return this.store.loadJSON<Todo[]>('joist_todo').then((todos) => {
this.initialized = true;

if (stored) {
this.todos = stored;
}
if (todos) {
this.todos = todos;
}

return this.todos;
});
}

addTodo(todo: Todo) {
async addTodo(todo: Todo) {
this.todos.push(todo);

await this.sync();

this.dispatchEvent(new TodoAddedEvent(todo));
this.sync();
}

removeTodo(id: string) {
async removeTodo(id: string) {
this.todos = this.todos.filter((todo) => todo.id !== id);

await this.sync();

this.dispatchEvent(new TodoRemovedEvent(id));
this.sync();
}

updateTodo(id: string, patch: Partial<Todo>) {
async updateTodo(id: string, patch: Partial<Todo>) {
for (let i = 0; i < this.todos.length; i++) {
if (this.todos[i].id === id) {
this.todos[i] = { ...this.todos[i], ...patch };

await this.sync();

this.dispatchEvent(new TodoUpdatedEvent(this.todos[i]));
this.sync();

break;
}
}
}

listen(event: string, cb: EventListener) {
this.addEventListener(event, cb);

return () => {
this.removeEventListener(event, cb);
};
}

private sync() {
this.store.saveJSON('joist_todo', this.todos);
return this.store.saveJSON('joist_todo', this.todos);
}
}
16 changes: 8 additions & 8 deletions integration/own/src/storage.ctx.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { injectable } from '@joist/di';

import { AppStorage } from './services/storage.service';
import { AppStorage, Storage } from './services/storage.service';
import { TodoService } from './services/todo.service';

class AppLocalStorage extends AppStorage {
loadJSON<T>(key: string): T | undefined {
class AppLocalStorage implements Storage {
loadJSON<T>(key: string): Promise<T | undefined> {
try {
const res = localStorage.getItem(key);

if (res) {
return JSON.parse(res);
return Promise.resolve(JSON.parse(res));
}
} catch {}

return undefined;
return Promise.resolve(undefined);
}

saveJSON<T extends object>(key: string, val: T): boolean {
saveJSON<T>(key: string, val: T): Promise<boolean> {
try {
localStorage.setItem(key, JSON.stringify(val));

return true;
return Promise.resolve(true);
} catch {
return false;
return Promise.resolve(false);
}
}
}
11 changes: 10 additions & 1 deletion integration/own/src/todo-card.element.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { styled, css } from '@joist/styled';
import { attr, UpgradableElement, observable, observe, OnPropertyChanged } from '@joist/observable';
import { query } from '@joist/query';

import { TodoStatus } from './services/todo.service';
import { Todo, TodoStatus } from './services/todo.service';

const template = document.createElement('template');
template.innerHTML = /*html*/ `
@@ -18,6 +18,15 @@ template.innerHTML = /*html*/ `
@styled
@observable
export class TodoCardElement extends UpgradableElement implements OnPropertyChanged {
static create(todo: Todo) {
const card = new TodoCardElement();
card.id = todo.id;
card.status = todo.status;
card.innerHTML = todo.name;

return card;
}

static styles = [
css`
:host {
20 changes: 8 additions & 12 deletions integration/own/src/todo-form.element.ts
Original file line number Diff line number Diff line change
@@ -66,27 +66,23 @@ export class TodoFormElement extends UpgradableElement {

@query('#input') input!: HTMLInputElement;

constructor(private todo: Injected<TodoService>) {
constructor(private getTodo: Injected<TodoService>) {
super();

const root = this.attachShadow({ mode: 'open' });
const shadow = this.attachShadow({ mode: 'open' });

root.appendChild(template.content.cloneNode(true));
shadow.appendChild(template.content.cloneNode(true));

root.addEventListener('submit', (e) => {
this.onSubmit(e);
});
shadow.addEventListener('submit', this.#onSubmit.bind(this));
}

private onSubmit(e: Event) {
const service = this.todo();
#onSubmit(e: Event) {
const service = this.getTodo();

e.preventDefault();

const todo = this.input.value;

if (todo.length) {
service.addTodo(Todo.create(todo, TodoStatus.Active));
if (this.input.value) {
service.addTodo(Todo.create(this.input.value, TodoStatus.Active));

this.input.value = '';
}
Loading