~evanj/wigly

28e10bda46c016404c432252b956502af28ddcea — Evan M Jones 1 year, 8 months ago 9169870
don't call old updater functions!
4 files changed, 25 insertions(+), 2 deletions(-)

M package.json
M src/main.js
M src/wigly/state.js
M src/wigly/transformer.js
M package.json => package.json +1 -1
@@ 1,6 1,6 @@
{
  "name": "wigly",
  "version": "0.5.9",
  "version": "0.5.10",
  "main": "dist/wigly.es5.js",
  "scripts": {
    "start": "npm run start:clean && npm run start:gcc && npm run start:gzip",

M src/main.js => src/main.js +4 -0
@@ 5,3 5,7 @@ if (typeof module !== "undefined") {
} else {
  window["wigly"] = wigly;
}

// export default wigly;
// export let state = wigly.state;
// export let effect = wigly.effect;

M src/wigly/state.js => src/wigly/state.js +11 -0
@@ 17,6 17,17 @@ export let state = init => {
    val,
    next => {
      curr.states[key] = next;
      // defer(() => {
      //   // console.log(curr.test().update);
      //   // console.log(curr.update);
      //   console.log(curr.test().update === curr.update);

      //   let updater = curr.test().update || curr.update;
      //   updater();

      //   // curr.update();
      //   // curr.test().update();
      // });
      defer(curr.update);
    }
  ];

M src/wigly/transformer.js => src/wigly/transformer.js +9 -1
@@ 16,13 16,21 @@ export let transformer = (spec, getEnv, giveEnv, giveVDOM, updateVDOM) => {
    let lastvdom;

    let self = {
      f,
      states: [],
      effects: [],
      children: {},
      ...getEnv(f, props.key),
      env: () => getEnv(f, props.key),
      iter: 0,
      update: () => {
        // Fishy business -- we have references to old updater functions
        // within state setters. Don't call these! Get latest and all is well. :)
        let { env } = getEnv(f, props.key);
        if (env && env().update !== self.update) {
          env().update();
          return;
        }

        transformer(
          spec,
          getEnv,