Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation #3

Closed
betula opened this issue Jun 17, 2020 · 22 comments
Closed

Implementation #3

betula opened this issue Jun 17, 2020 · 22 comments

Comments

@betula
Copy link
Member

betula commented Jun 17, 2020

const TickerService = unit({
  current: 0,
  get next() {
    return this.current + 1;
  },
  tick() {
    this.current += 1;
  },
  constructor() {},
  destructor() {}
});

const ticker = new TickerService();
ticker.tick();
console.log(ticker.next);

function action(fn) {
  return fn;
}
function computed(fn) {
  return fn;
}
function setting() {}
function getting() {}

function unit(schema) {
  const source = Object.getOwnPropertyDescriptors(schema);
  const DataKey = "data";
  const descriptors = {};

  Object.keys(source).forEach(key => {
    const { value, get, set } = source[key];
    const descriptor = {};
    if (typeof value === "function") {
      descriptor.value = action(value);
    } else if (get) {
      descriptor.get = computed(get);
      if (set) {
        descriptor.set = action(set);
      }
    } else {
      descriptor.set = function(val) {
        (this[DataKey] = this[DataKey] || {})[key] = val;
        setting();
      };
      descriptor.get = function() {
        const val = (this[DataKey] = this[DataKey] || {})[key] || value;
        getting();
        return val;
      };
    }
    descriptors[key] = descriptor;
  });

  let constructor = source.constructor && source.constructor.value;
  if (constructor) {
    constructor = action(constructor);
  }
  const Class = function() {
    if (constructor) {
      constructor.apply(this, arguments);
    }
  };
  Class.prototype = Object.defineProperties({}, descriptors);
  return Class;
}

https://codesandbox.io/s/elastic-fermi-or16g?file=/src/index.js:0-1406

@betula
Copy link
Member Author

betula commented Jun 17, 2020

Article titles:
React microfrontends
React state management for micro-frontends

@betula
Copy link
Member Author

betula commented Jun 17, 2020

@betula
Copy link
Member Author

betula commented Jun 20, 2020

@betula
Copy link
Member Author

betula commented Jun 21, 2020

@betula
Copy link
Member Author

betula commented Jun 22, 2020

@betula
Copy link
Member Author

betula commented Jun 22, 2020

@betula
Copy link
Member Author

betula commented Jun 22, 2020

@betula
Copy link
Member Author

betula commented Jun 22, 2020

@betula
Copy link
Member Author

betula commented Jun 22, 2020

@betula
Copy link
Member Author

betula commented Jun 22, 2020

https://codesandbox.io/s/condescending-matsumoto-5nuov

@betula
Copy link
Member Author

betula commented Jun 23, 2020

@betula
Copy link
Member Author

betula commented Jun 23, 2020

https://codesandbox.io/s/focused-maxwell-p5y57

@betula
Copy link
Member Author

betula commented Jun 23, 2020

https://codesandbox.io/s/kind-rosalind-7iztm

@betula
Copy link
Member Author

betula commented Jun 23, 2020

https://codesandbox.io/s/upbeat-ptolemy-nq01d

@betula
Copy link
Member Author

betula commented Jun 23, 2020

@betula
Copy link
Member Author

betula commented Jun 23, 2020

@betula
Copy link
Member Author

betula commented Jun 23, 2020

https://codesandbox.io/s/beautiful-firefly-bn0ly

@betula
Copy link
Member Author

betula commented Jun 23, 2020

https://codesandbox.io/s/flamboyant-hooks-yhsg8

@betula
Copy link
Member Author

betula commented Jun 23, 2020

@betula
Copy link
Member Author

betula commented Jun 23, 2020

@betula
Copy link
Member Author

betula commented Jun 24, 2020

#2

@betula betula closed this as completed Jun 24, 2020
@betula
Copy link
Member Author

betula commented Jun 24, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant