1.0.32 • Published 7 years ago

@tandem/sandbox v1.0.32

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

Kitchen sink example:

import { Kernel } from "@tandem/common";
import { SyntheticWindow, SyntheticDocument } from "@tandem/synthetic-browser";
import {
  Sandbox,
  Dependency,
  FileCacheItem,
  LocalFileSystem,
  DependencyGraph,
  ISyntheticObject,
  LocalFileResolver,
  FileSystemProvider,
  FileEditorProvider,
  FileResolverProvider,
  DependencyGraphProvider,
  ContentEditorFactoryProvider,
  DependencyLoaderFactoryProvider,
} from "@tandem/sandbox";


const kernel = new Kernel(
  new DependencyGraphProvider(),
  new FileEditorProvider(),
  new FileSystemProvider(new LocalFileSystem()),
  new FileResolverProvider(new LocalFileResolver()),
  new DependencyLoaderFactoryProvider("text/css", CSSDependencyLoader),
  new ContentEditorFactoryProvider("text/css", CSSContentEditor),
);

// fetch the dependency graph singleton
const dependencyGraph: DependencyGraph = DependencyGraphProvider.getInstance("webpack", kernel);

const sandbox = new Sandbox(deps, function createGlobal() {

  // global environment context -- browser, node, etc
  return new SyntheticWindow();
});

// create an dependency entry -- all dependencies, and nested dependencies
// be dependency up into this object.
const fileDependency: Dependency = dependencyGraph.getDependency("file:///path/to/local/file.html");

// execute the file dependency. Re-execute if the dependency changes
const fakeDocument: SyntheticDocument = await sandbox.open(fileDependency);

const edit = fakeDocument.body.createEdit().appendChild(fakeDocument.createTextNode("hello world")));

// the synthetic object edit maintains a reference back to the source file -- where it patches changes --
// file:///path/to/local/file.html in this case.
FileEditorProvider.getInstance(deps).applyMutations(...edit.mutations);

Diffing & patching synthetic objects example:

import { SyntheticWindow } from "@tandem/synthetic-browser";
import { SyntheticObjectTreeEditor } from "@tandem/sandbox";

const { document } = new SyntheticWindow();
document.body.innerHTML = `Hello World`;

const documentClone = document.cloneNode(true);
documentClone.body.innerHTML = `Hello Again!`;

// create a diff from a newer node
const edit = document.createEdit().fromDiff(documentClone);

// apply the edit to the original document
new SyntheticObjectTreeEditor(document).applyMutations(...edit.mutations);

// this also works
// edit.applyMutationsTo(document);
1.0.32

7 years ago

1.0.31

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.0

7 years ago