mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 14:45:56 +00:00
Add support for updating instances defined in project nodes
This commit is contained in:
@@ -12,7 +12,7 @@ use rbx_dom_weak::RbxId;
|
|||||||
use crate::{
|
use crate::{
|
||||||
message_queue::MessageQueue,
|
message_queue::MessageQueue,
|
||||||
snapshot::{apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, RojoTree},
|
snapshot::{apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, RojoTree},
|
||||||
snapshot_middleware::{snapshot_from_vfs, InstanceSnapshotContext},
|
snapshot_middleware::{snapshot_from_vfs, snapshot_project_node, InstanceSnapshotContext},
|
||||||
vfs::{Vfs, VfsEvent, VfsFetcher},
|
vfs::{Vfs, VfsEvent, VfsFetcher},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,22 +139,24 @@ fn update_affected_instances<F: VfsFetcher>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: Use persisted snapshot context struct instead of recreating it
|
||||||
|
// every time.
|
||||||
|
let mut snapshot_context = InstanceSnapshotContext::default();
|
||||||
|
|
||||||
let snapshot = match instigating_source {
|
let snapshot = match instigating_source {
|
||||||
InstigatingSource::Path(path) => {
|
InstigatingSource::Path(path) => {
|
||||||
let entry = vfs
|
let entry = vfs
|
||||||
.get(path)
|
.get(path)
|
||||||
.expect("could not get instigating path from filesystem");
|
.expect("could not get instigating path from filesystem");
|
||||||
|
|
||||||
// TODO: Use persisted snapshot
|
snapshot_from_vfs(&mut snapshot_context, &vfs, &entry)
|
||||||
// context struct instead of
|
|
||||||
// recreating it every time.
|
|
||||||
snapshot_from_vfs(&mut InstanceSnapshotContext::default(), &vfs, &entry)
|
|
||||||
.expect("snapshot failed")
|
.expect("snapshot failed")
|
||||||
.expect("snapshot did not return an instance")
|
.expect("snapshot did not return an instance")
|
||||||
}
|
}
|
||||||
InstigatingSource::ProjectNode(_, _) => {
|
InstigatingSource::ProjectNode(instance_name, project_node) => {
|
||||||
log::warn!("Instance {} had an instigating source that was a project node, which is not yet supported.", id);
|
snapshot_project_node(&mut snapshot_context, instance_name, project_node, &vfs)
|
||||||
continue;
|
.expect("snapshot failed")
|
||||||
|
.expect("snapshot did not return an instance")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -311,4 +311,57 @@ mod serve_session {
|
|||||||
view_tree(&session.tree(), &mut redactions)
|
view_tree(&session.tree(), &mut redactions)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn change_file_in_project() {
|
||||||
|
let (state, fetcher) = TestFetcher::new();
|
||||||
|
|
||||||
|
state.load_snapshot(
|
||||||
|
"/foo",
|
||||||
|
VfsSnapshot::dir(hashmap! {
|
||||||
|
"default.project.json" => VfsSnapshot::file(r#"
|
||||||
|
{
|
||||||
|
"name": "change_file_in_project",
|
||||||
|
"tree": {
|
||||||
|
"$className": "Folder",
|
||||||
|
|
||||||
|
"Child": {
|
||||||
|
"$path": "file.txt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#),
|
||||||
|
"file.txt" => VfsSnapshot::file("initial content"),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
let vfs = Vfs::new(fetcher);
|
||||||
|
let session = ServeSession::new(vfs, "/foo");
|
||||||
|
|
||||||
|
let mut redactions = RedactionMap::new();
|
||||||
|
assert_yaml_snapshot!(
|
||||||
|
"change_file_in_project_before",
|
||||||
|
view_tree(&session.tree(), &mut redactions)
|
||||||
|
);
|
||||||
|
|
||||||
|
state.load_snapshot("/foo/file.txt", VfsSnapshot::file("Changed!"));
|
||||||
|
|
||||||
|
let receiver = session.message_queue().subscribe_any();
|
||||||
|
|
||||||
|
state.raise_event(VfsEvent::Modified(PathBuf::from("/foo/file.txt")));
|
||||||
|
|
||||||
|
let receiver = Timeout::new(receiver, Duration::from_millis(200));
|
||||||
|
|
||||||
|
let mut rt = Runtime::new().unwrap();
|
||||||
|
let result = rt.block_on(receiver).unwrap();
|
||||||
|
|
||||||
|
assert_yaml_snapshot!(
|
||||||
|
"change_file_in_project_patch",
|
||||||
|
redactions.redacted_yaml(result)
|
||||||
|
);
|
||||||
|
assert_yaml_snapshot!(
|
||||||
|
"change_file_in_project_after",
|
||||||
|
view_tree(&session.tree(), &mut redactions)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ use self::{
|
|||||||
};
|
};
|
||||||
use crate::vfs::{Vfs, VfsEntry, VfsFetcher};
|
use crate::vfs::{Vfs, VfsEntry, VfsFetcher};
|
||||||
|
|
||||||
|
pub use self::project::snapshot_project_node;
|
||||||
|
|
||||||
macro_rules! middlewares {
|
macro_rules! middlewares {
|
||||||
( $($middleware: ident,)* ) => {
|
( $($middleware: ident,)* ) => {
|
||||||
/// Generates a snapshot of instances from the given VfsEntry.
|
/// Generates a snapshot of instances from the given VfsEntry.
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl SnapshotMiddleware for SnapshotProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot_project_node<F: VfsFetcher>(
|
pub fn snapshot_project_node<F: VfsFetcher>(
|
||||||
context: &mut InstanceSnapshotContext,
|
context: &mut InstanceSnapshotContext,
|
||||||
instance_name: &str,
|
instance_name: &str,
|
||||||
node: &ProjectNode,
|
node: &ProjectNode,
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
---
|
||||||
|
source: src/serve_session.rs
|
||||||
|
expression: "view_tree(&session.tree(), &mut redactions)"
|
||||||
|
---
|
||||||
|
id: id-1
|
||||||
|
name: change_file_in_project
|
||||||
|
class_name: Folder
|
||||||
|
properties: {}
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: true
|
||||||
|
instigating_source:
|
||||||
|
Path: /foo/default.project.json
|
||||||
|
relevant_paths:
|
||||||
|
- /foo/default.project.json
|
||||||
|
children:
|
||||||
|
- id: id-2
|
||||||
|
name: Child
|
||||||
|
class_name: StringValue
|
||||||
|
properties:
|
||||||
|
Value:
|
||||||
|
Type: String
|
||||||
|
Value: Changed!
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
instigating_source:
|
||||||
|
ProjectNode:
|
||||||
|
- Child
|
||||||
|
- class_name: ~
|
||||||
|
children: {}
|
||||||
|
properties: {}
|
||||||
|
ignore_unknown_instances: ~
|
||||||
|
path: "/foo\\file.txt"
|
||||||
|
relevant_paths:
|
||||||
|
- /foo/file.txt
|
||||||
|
- /foo/file.meta.json
|
||||||
|
children: []
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
---
|
||||||
|
source: src/serve_session.rs
|
||||||
|
expression: "view_tree(&session.tree(), &mut redactions)"
|
||||||
|
---
|
||||||
|
id: id-1
|
||||||
|
name: change_file_in_project
|
||||||
|
class_name: Folder
|
||||||
|
properties: {}
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: true
|
||||||
|
instigating_source:
|
||||||
|
Path: /foo/default.project.json
|
||||||
|
relevant_paths:
|
||||||
|
- /foo/default.project.json
|
||||||
|
children:
|
||||||
|
- id: id-2
|
||||||
|
name: Child
|
||||||
|
class_name: StringValue
|
||||||
|
properties:
|
||||||
|
Value:
|
||||||
|
Type: String
|
||||||
|
Value: initial content
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
instigating_source:
|
||||||
|
ProjectNode:
|
||||||
|
- Child
|
||||||
|
- class_name: ~
|
||||||
|
children: {}
|
||||||
|
properties: {}
|
||||||
|
ignore_unknown_instances: ~
|
||||||
|
path: "/foo\\file.txt"
|
||||||
|
relevant_paths:
|
||||||
|
- /foo/file.txt
|
||||||
|
- /foo/file.meta.json
|
||||||
|
children: []
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
source: src/serve_session.rs
|
||||||
|
expression: redactions.redacted_yaml(result)
|
||||||
|
---
|
||||||
|
- 1
|
||||||
|
- - removed: []
|
||||||
|
added: []
|
||||||
|
updated:
|
||||||
|
- id: id-2
|
||||||
|
changed_name: ~
|
||||||
|
changed_class_name: ~
|
||||||
|
changed_properties:
|
||||||
|
Value:
|
||||||
|
Type: String
|
||||||
|
Value: Changed!
|
||||||
|
changed_metadata: ~
|
||||||
Reference in New Issue
Block a user