Add m.prop (#2268)

Fixes #2095
This commit is contained in:
Isiah Meadows 2018-11-07 12:18:55 -05:00 committed by GitHub
parent 75626b30db
commit 6042b001f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 203 additions and 1 deletions

9
util/prop.js Normal file
View file

@ -0,0 +1,9 @@
"use strict"
module.exports = function (store) {
return {
get: function() { return store },
toJSON: function() { return store },
set: function(value) { return store = value }
}
}

View file

@ -8,8 +8,10 @@
<script src="../../ospec/ospec.js"></script>
<script src="../../util/withAttr.js"></script>
<script src="../../util/prop.js"></script>
<script src="test-withAttr.js"></script>
<script src="test-prop.js"></script>
<script>require("../../ospec/ospec").run()</script>
</body>
</html>

16
util/tests/test-prop.js Normal file
View file

@ -0,0 +1,16 @@
"use strict"
var o = require("../../ospec/ospec")
var prop = require("../../util/prop")
o.spec("prop", function() {
o("works", function() {
var p = prop(1)
o(p.get()).equals(1)
o(p.toJSON()).equals(1)
o(p.set(2)).equals(2)
o(p.get()).equals(2)
o(p.toJSON()).equals(2)
})
})