-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5080 from dodona-edu/chore/update-lit-3
Upgrade to lit 3.0
- Loading branch information
Showing
10 changed files
with
99 additions
and
162 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
app/assets/javascripts/components/annotations/code_listing_row.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
app/assets/javascripts/components/annotations/hidden_annotations_dot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 11 additions & 54 deletions
65
app/assets/javascripts/state/state_system/StateProperty.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,25 @@ | ||
import { State } from "./State"; | ||
import { ClassElement, Constructor } from "@lit/reactive-element/decorators/base.js"; | ||
|
||
/** | ||
* This function is used to decorate a property of a State class. | ||
* It will make the property reactive and will dispatch a StateEvent when the property changes. | ||
* It will also record every read of the property to the stateRecorder. | ||
* @param stateClass | ||
* @param property | ||
* Function for decorating a property that is compatible with both TypeScript decorators. | ||
* It will keep track of readers and dispatch events when the property is changed. | ||
* | ||
* @returns {void} | ||
*/ | ||
function finisher(stateClass: typeof State, property: PropertyKey): void { | ||
const key = typeof property === "symbol" ? Symbol() : `__${property}`; | ||
const currentVal = stateClass.prototype[property]; | ||
Object.defineProperty(stateClass.prototype, property, { | ||
export const stateProperty = (proto: State, name?: PropertyKey): void => { | ||
const key = typeof name === "symbol" ? Symbol() : `__${name}`; | ||
const currentVal = proto[name]; | ||
Object.defineProperty(proto, name, { | ||
get(): unknown { | ||
this.recordRead(property); | ||
this.recordRead(name); | ||
return this[key]; | ||
}, | ||
set(value: unknown) { | ||
this[key] = value; | ||
this.dispatchStateEvent(property); | ||
this.dispatchStateEvent(name); | ||
}, | ||
configurable: true, | ||
enumerable: true, | ||
}); | ||
stateClass.prototype[key] = currentVal; | ||
} | ||
|
||
/** | ||
* Function for decorating a property that is compatible with both TypeScript and Babel decorators. | ||
* It will apply the `finisher` function to the property. | ||
* | ||
* @returns {ClassElement|void} | ||
*/ | ||
export const stateProperty = ( | ||
protoOrDescriptor: State | ClassElement, | ||
name?: PropertyKey | ||
// Note TypeScript requires the return type to be `void|any` | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
): void | any => { | ||
if (name !== undefined) { | ||
// TypeScript / Babel legacy mode | ||
const ctor = (protoOrDescriptor as State).constructor as typeof State; | ||
Object.defineProperty(protoOrDescriptor, name, { | ||
writable: true, | ||
configurable: true, | ||
enumerable: true | ||
}); | ||
finisher(ctor, name); | ||
} else { | ||
// Babel standard mode | ||
const element = protoOrDescriptor as ClassElement; | ||
return { | ||
kind: "field", | ||
placement: "prototype", | ||
key: Symbol(), | ||
descriptor: {}, | ||
finisher: function <State> (ctor: Constructor<State>) { | ||
finisher(ctor as typeof State, element.key); | ||
}, | ||
initializer(this: {[key: symbol]: unknown}) { | ||
if (typeof element.initializer === "function") { | ||
this[element.key] = element.initializer.call(this); | ||
} | ||
}, | ||
}; | ||
} | ||
proto[key] = currentVal; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.