Skip to content

Commit

Permalink
Major updates for v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Jul 18, 2019
1 parent c4323e9 commit bba5d9e
Show file tree
Hide file tree
Showing 16 changed files with 601 additions and 1,530 deletions.
21 changes: 4 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,19 @@ module.exports = {
output: 'path-to-output/filename.js',
variables: {
imports: [ `import S from 's-js'` ],
computed: 'S',
sample: 'S.sample',
root: 'S.root',
cleanup: 'S.cleanup'
declarations: {
wrap: 'S',
}
}
}
```

These symbols should reference an observable API with the following functionality:

### computed(fn) : void
### wrap(fn) : void

This is used to wrap all expressions in computations. Your wrap method is expected to call fn with the previously evaluated value if the arity is 1 to allow for reducing computations.

### root(fn) : any

This indicates a new disposable context. The fn should be provided a dispose method that can be called to free all computations in the context.

### sample(fn) : any

A method that causes dependencies within not to be tracked.

### cleanup(fn) : void

This method should register a cleanup method to be called when the context is released.

Then you run the cli command:
```sh
> dom-expressions
Expand Down
9 changes: 6 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// babel.config.js
module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
plugins: [['babel-plugin-jsx-dom-expressions', {moduleName: './runtime.js'}]]
env: {
test: {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
plugins: [['babel-plugin-jsx-dom-expressions', {moduleName: './runtime.js', alwaysCreateComponents: true}]]
}
}
};
37 changes: 3 additions & 34 deletions dom-expressions.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,9 @@ module.exports = {
output: 'test/runtime.js',
variables: {
imports: [ `import {
comp as wrap, sample, root, cleanup, getContextOwner as currentContext,
setContext, makeDataNode, value
comp as wrap, getContextOwner as currentContext,
} from '@ryansolid/s-js'` ],
declarations: {
memo: `(fn) => {
const s = value(fn());
wrap(() => s(fn()));
return s;
}`,
SuspenseContext: `{
id: 'suspense', initFn: () => {
let counter = 0;
const s = makeDataNode(),
store = {
increment: () => ++counter === 1 && !store.initializing && s.next(),
decrement: () => --counter === 0 && s.next(),
suspended: () => {
s.current();
return counter;
},
initializing: true
}
return store;
}
}`,
registerSuspense: `(fn) => {
wrap(() => {
const c = SuspenseContext.initFn();
setContext(SuspenseContext.id, c);
fn(c);
c.initializing = false;
});
}`
},
includeContext: true
includeContext: true,
classComponents: true
}
}
Loading

0 comments on commit bba5d9e

Please sign in to comment.