Skip to content

Commit

Permalink
fix: failed to use changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Jun 12, 2024
1 parent 94864fe commit 2484a49
Show file tree
Hide file tree
Showing 6 changed files with 4,535 additions and 5,646 deletions.
2 changes: 1 addition & 1 deletion packages/basic/src/widgets/figures/figure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class Figure extends Widget {
options ??= {}
super(options)
options.style ??= {}
this.style.color = reactive(options.style.color ?? Color.WHITE)
this.style.borderColor = reactive(options.style.borderColor ?? options.style.color ?? Color.WHITE)
this.style.borderShader = reactive(options.style.borderShader ?? options.style.shader)
this.style.borderWidth = ref(options.style.borderWidth ?? 2)
this.style.fillColor = reactive(options.style.fillColor ?? options.style.color ?? Color.WHITE)
this.style.fillShader = reactive(options.style.fillShader ?? options.style.shader)
this.style.color = reactive(options.style.color ?? Color.WHITE)
this.style.shader = reactive(options.style.shader)
this.style.fill = ref(options.style.fill ?? true)
this.style.border = ref(options.style.border ?? false)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface Animation<T> {

export type Anim<T> = WithDep<() => boolean, AnimationContext<T>>

export type TimingFunction = (process: number) => number
export const linear: TimingFunction = p => p
type TimingFunction = (process: number) => number
const linear: TimingFunction = p => p
export interface BasicAnimAttrs {
process: number
duration: number
Expand Down
60 changes: 33 additions & 27 deletions packages/core/src/prop.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isUndefined } from '@newcar/utils'

export interface PropertyWithChange<T> {
$onPostChanged: (listener: Listener<T>) => void
$onPreChanged: (listener: Listener<T>) => void
Expand All @@ -12,25 +14,27 @@ function _reactive<T>(value: T, listener?: Listener<T>, reactType: number = 1) {
const postListeners: Listener<T>[] = listener ? [listener] : []
const preListeners: Listener<T>[] = []

Object.defineProperty(value, '$onPostChanged', {
value: (listener: Listener<T>) => {
postListeners.push(listener)
},
writable: false,
configurable: false,
})
Object.defineProperty(value, '$onPreChanged', {
value: (listener: Listener<T>) => {
preListeners.push(listener)
},
writable: false,
configurable: false,
})
Object.defineProperty(value, REACTIVE_TAG, {
value: reactType,
writable: false,
configurable: false,
})
if (!isUndefined(value)) {
Object.defineProperty(value, '$onPostChanged', {
value: (listener: Listener<T>) => {
postListeners.push(listener)
},
writable: false,
configurable: false,
})
Object.defineProperty(value, '$onPreChanged', {
value: (listener: Listener<T>) => {
preListeners.push(listener)
},
writable: false,
configurable: false,
})
Object.defineProperty(value, REACTIVE_TAG, {
value: reactType,
writable: false,
configurable: false,
})
}

return new Proxy(value, {
get(target, prop) {
Expand Down Expand Up @@ -69,15 +73,17 @@ export function changed<T>(
) {
const withChanged = target as PropertyWithChange<T>

if (typeof listener === 'function') {
withChanged.$onPostChanged(listener)
}
else {
if (listener.postChanged) {
withChanged.$onPostChanged(listener.postChanged)
if (!isUndefined(target)) {
if (typeof listener === 'function') {
withChanged.$onPostChanged(listener)
}
if (listener.preChanged) {
withChanged.$onPreChanged(listener.preChanged)
else {
if (listener.postChanged) {
withChanged.$onPostChanged(listener.postChanged)
}
if (listener.preChanged) {
withChanged.$onPreChanged(listener.preChanged)
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ export class Widget {

// Run an animation with respect to `elapsed`, which is maintained by `App` class
runAnimation(elapsed: number, ck: CanvasKit) {
if (this.animationInstances.length === 0)
return
if (this.animationInstances[0].build(
{ ck, elapsed, widget: this },
)()) {
Expand Down
14 changes: 11 additions & 3 deletions packages/utils/src/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ export class Color {
return new Color(r, g, b, a)
}

static readonly WHITE = Color.rgba(255, 255, 255)
static readonly BLACK = Color.rgba(0, 0, 0)
static readonly TRANSPARENT = Color.rgba(0, 0, 0, 0)
static get WHITE() {
return Color.rgba(255, 255, 255)
}

static get BLACK() {
return Color.rgba(0, 0, 0)
}

static get TRANSPARENT() {
return Color.rgba(0, 0, 0, 0)
}
}
Loading

0 comments on commit 2484a49

Please sign in to comment.