-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAttributes.swift
More file actions
30 lines (24 loc) · 885 Bytes
/
Attributes.swift
File metadata and controls
30 lines (24 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import JavaScriptKit
@propertyWrapper public struct ReadWriteAttribute<Wrapped: JSValueCompatible> {
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString
@inlinable public init(jsObject: JSObject, name: JSString) {
self.jsObject = jsObject
self.name = name
}
@inlinable public var wrappedValue: Wrapped {
get { jsObject[name].fromJSValue()! }
nonmutating set { jsObject[name] = newValue.jsValue }
}
}
@propertyWrapper public struct ReadonlyAttribute<Wrapped: ConstructibleFromJSValue> {
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString
@inlinable public init(jsObject: JSObject, name: JSString) {
self.jsObject = jsObject
self.name = name
}
@inlinable public var wrappedValue: Wrapped {
jsObject[name].fromJSValue()!
}
}