@quenty/valuebaseutils 7.10.0 → 7.11.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [7.11.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valuebaseutils@7.10.0...@quenty/valuebaseutils@7.11.0) (2023-04-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add RxValueBaseUtils.observe(parent, className, name, defaultValue) ([173d598](https://github.com/Quenty/NevermoreEngine/commit/173d59877d82d4d12740937a2aa333b3659ab1d3))
12
+ * Add ValueBaseValue for single-value API interface ([8bfa878](https://github.com/Quenty/NevermoreEngine/commit/8bfa878565611f68f489a528485a459cb1c0339e))
13
+
14
+
15
+
16
+
17
+
6
18
  # [7.10.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valuebaseutils@7.9.0...@quenty/valuebaseutils@7.10.0) (2023-04-03)
7
19
 
8
20
  **Note:** Version bump only for package @quenty/valuebaseutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/valuebaseutils",
3
- "version": "7.10.0",
3
+ "version": "7.11.0",
4
4
  "description": "Provides utilities for working with valuesbase objects, like IntValue or ObjectValue in Roblox.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,13 +25,13 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/brio": "^8.9.0",
29
- "@quenty/instanceutils": "^7.10.0",
28
+ "@quenty/brio": "^8.10.0",
29
+ "@quenty/instanceutils": "^7.11.0",
30
30
  "@quenty/loader": "^6.2.0",
31
31
  "@quenty/promise": "^6.4.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "fa7c7edfd754cf18fd808466121310f9bfff6271"
36
+ "gitHead": "d26d804d1f96e9a0f3f5687f8e024ec9d476172d"
37
37
  }
@@ -41,6 +41,10 @@ end
41
41
  @return Observable<Brio<any>>
42
42
  ]=]
43
43
  function RxValueBaseUtils.observeBrio(parent, className, name)
44
+ assert(typeof(parent) == "Instance", "Bad parent")
45
+ assert(type(className) == "string", "Bad className")
46
+ assert(type(name) == "string", "Bad naem")
47
+
44
48
  return RxInstanceUtils.observeLastNamedChildBrio(parent, className, name)
45
49
  :Pipe({
46
50
  RxBrioUtils.switchMapBrio(function(valueObject)
@@ -50,6 +54,26 @@ function RxValueBaseUtils.observeBrio(parent, className, name)
50
54
  })
51
55
  end
52
56
 
57
+ --[=[
58
+ Observes a value base underneath a parent
59
+
60
+ @param parent Instance
61
+ @param className string
62
+ @param name string
63
+ @param defaultValue any
64
+ @return Observable<any>
65
+ ]=]
66
+ function RxValueBaseUtils.observe(parent, className, name, defaultValue)
67
+ assert(typeof(parent) == "Instance", "Bad parent")
68
+ assert(type(className) == "string", "Bad className")
69
+ assert(type(name) == "string", "Bad name")
70
+
71
+ return RxValueBaseUtils.observeBrio(parent, className, name)
72
+ :Pipe({
73
+ RxBrioUtils.emitOnDeath(defaultValue)
74
+ })
75
+ end
76
+
53
77
 
54
78
  --[=[
55
79
  Observables a given value object's value
@@ -0,0 +1,67 @@
1
+ --[=[
2
+ For when attributes don't work
3
+
4
+ @class ValueBaseValue
5
+ ]=]
6
+
7
+ local require = require(script.Parent.loader).load(script)
8
+
9
+ local RunService = game:GetService("RunService")
10
+
11
+ local ValueBaseUtils = require("ValueBaseUtils")
12
+ local RxValueBaseUtils = require("RxValueBaseUtils")
13
+
14
+ local ValueBaseValue = {}
15
+ ValueBaseValue.ClassName = "ValueBaseValue"
16
+ ValueBaseValue.__index = ValueBaseValue
17
+
18
+ function ValueBaseValue.new(parent, className, name, defaultValue)
19
+ assert(typeof(parent) == "Instance", "Bad argument 'parent'")
20
+ assert(type(className) == "string", "Bad argument 'className'")
21
+ assert(type(name) == "string", "Bad argument 'name'")
22
+
23
+ local self = {}
24
+
25
+ self._parent = parent
26
+ self._name = name
27
+ self._className = className
28
+ self._defaultValue = defaultValue
29
+
30
+ -- Initialize on the server
31
+ if RunService:IsServer() then
32
+ ValueBaseUtils.getOrCreateValue(parent, self._className, self._name, self._defaultValue)
33
+ end
34
+
35
+ return setmetatable(self, ValueBaseValue)
36
+ end
37
+
38
+ function ValueBaseValue:ObserveBrio()
39
+ return RxValueBaseUtils.observeBrio(self._parent, self._className, self._name)
40
+ end
41
+
42
+ function ValueBaseValue:Observe()
43
+ return RxValueBaseUtils.observe(self._parent, self._className, self._name, self._defaultValue)
44
+ end
45
+
46
+ function ValueBaseValue:__index(index)
47
+ if index == "Value" then
48
+ return ValueBaseUtils.getValue(self._parent, self._className, self._name, self._defaultValue)
49
+ elseif index == "Changed" then
50
+ error("Changed is not implemented")
51
+ elseif ValueBaseValue[index] or index == "_defaultValue" then
52
+ return ValueBaseValue[index]
53
+ else
54
+ error(("%q is not a member of ValueBaseValue"):format(tostring(index)))
55
+ end
56
+ end
57
+
58
+ function ValueBaseValue:__newindex(index, value)
59
+ if index == "Value" then
60
+ ValueBaseUtils.setValue(self._parent, self._className, self._name, value)
61
+ else
62
+ error(("%q is not a member of ValueBaseValue"):format(tostring(index)))
63
+ end
64
+ end
65
+
66
+
67
+ return ValueBaseValue