evanesce
Version:
Evanesce disappears your web application framework for desired routes by managing AOT page builds on dependency change.
52 lines (51 loc) • 2.42 kB
JavaScript
;
const evanesceExpress = {};
const signals = {};
const renderHomePage = {};
const renderProductPage = {};
// ============================================================================
// Setup Evanesce
// ============================================================================
const products = [{ value: 'fibityfoo', slug: 'fibity-foo', inventory: 1 }];
const signalKeys = [
{
key: 'reviews',
keys: products.map((product) => product.value)
},
{
key: 'inventory',
keys: products.map((product) => product.value)
}
];
const evanesce = evanesceExpress({ signalKeys });
// ============================================================================
// Setup Routes
// ============================================================================
evanesce.get('/', renderHomePage, [signals.reviews]);
evanesce.get('/product/:slug', renderProductPage, ({ value }) => [signals.inventory[value], signals.reviews[value]], products);
// ============================================================================
// Triggers
// ============================================================================
signals.reviews.fibityfoo.rebuildDependencies();
signals.reviews.rebuildDependencies();
signals.inventory.fibityfoo.rebuildDependencies();
signals.inventory.rebuildDependencies();
// ============================================================================
// What signals would look like
// ============================================================================
// Decided that children should trigger parents and not duplicate their list
// This takes less memory, and I have already decided on the first-class
// support of hierarchy with the api that got me here, so accept hierarchy.
signals.reviews.signalRebuilds = [{ fn: renderHomePage, route: '/' }];
signals.reviews.fibityfoo.signalRebuilds = [
{ fn: renderProductPage, route: '/product/fibity-foo' }
// Should it include the list of the parent as well:
// {fn: renderHomePage, route: '/'},
// or should it then trigger the parent and let the parent be responsible for it?
];
signals.inventory.signalRebuilds = [];
signals.inventory.fibityfoo.signalRebuilds = [
{ fn: renderProductPage, route: '/product/fibity-foo' }
// Should it include the list of the parent as well
// or should it then trigger the parent and let the parent be responsible for it?
];