fix(context): Allow removing a value at a pushed state
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/// A container for template variables.
|
/// A container for template variables.
|
||||||
public class Context {
|
public class Context {
|
||||||
var dictionaries: [[String: Any]]
|
var dictionaries: [[String: Any?]]
|
||||||
let namespace: Namespace
|
let namespace: Namespace
|
||||||
|
|
||||||
/// Initialise a Context with an optional dictionary and optional namespace
|
/// Initialise a Context with an optional dictionary and optional namespace
|
||||||
@@ -58,9 +58,11 @@ public class Context {
|
|||||||
|
|
||||||
for dictionary in dictionaries {
|
for dictionary in dictionaries {
|
||||||
for (key, value) in dictionary {
|
for (key, value) in dictionary {
|
||||||
|
if let value = value {
|
||||||
accumulator.updateValue(value, forKey: key)
|
accumulator.updateValue(value, forKey: key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return accumulator
|
return accumulator
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,15 @@ func testContext() {
|
|||||||
try expect(context["name"] as? String) == "Kyle"
|
try expect(context["name"] as? String) == "Kyle"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0.it("allows you to remove a parent's value in a level") {
|
||||||
|
try context.push {
|
||||||
|
context["name"] = nil
|
||||||
|
try expect(context["name"]).to.beNil()
|
||||||
|
}
|
||||||
|
|
||||||
|
try expect(context["name"] as? String) == "Kyle"
|
||||||
|
}
|
||||||
|
|
||||||
$0.it("allows you to push a dictionary and run a closure then restoring previous state") {
|
$0.it("allows you to push a dictionary and run a closure then restoring previous state") {
|
||||||
var didRun = false
|
var didRun = false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user