Skip to content

Space banking user interface#9

Closed
darko-mijic wants to merge 62 commits intodevelopfrom
feature/ui
Closed

Space banking user interface#9
darko-mijic wants to merge 62 commits intodevelopfrom
feature/ui

Conversation

@darko-mijic
Copy link
Copy Markdown
Member

No description provided.

@darko-mijic darko-mijic added the wip label Jul 1, 2016
@darko-mijic darko-mijic self-assigned this Jul 1, 2016
@darko-mijic
Copy link
Copy Markdown
Member Author

I found some time to work on this sample application. Next up is actual projection rebuilding and missing projections like summary. Here is what we have now:

screen shot 2016-07-01 at 14 56 56

@darko-mijic
Copy link
Copy Markdown
Member Author

We have buttons for invoking projection rebuilding. Implementation is currently very simple, there are not checks if projection rebuilding is already in progress.

screen shot 2016-07-01 at 17 14 32

@darko-mijic
Copy link
Copy Markdown
Member Author

This is not working, imports are undefined.

import { BankAccountOpened, BankAccountCredited, BankAccountDebited } from '../../domain/events';

Event definitions:

import Contact from './value-objects/contact';

export default Space.messaging.define(Space.domain.Event,  {

  BankAccountOpened: {
    owner: Contact,
    initialBalance: Money,
    overdraft: Money,
    currency: Currency
  },

  BankAccountCredited: {
    amount: Money
  },

  BankAccountDebited: {
    amount: Money
  }

});

Space.messaging.define helper:

Space.messaging.define = (BaseType, ...options) => {

  if (!BaseType.isSerializable) {
    throw new Error('BaseType must extend Space.messaging.Serializable');
  }

  let namespace = null;
  let definitions = null;
  let subTypes = {};

  switch (options.length) {
  case 0:
    throw new Error(`Space.messaging.define is missing options for defining sub typs of ${BaseType}.`);
  case 1:
    if (_.isObject(options[0])) {
      // VALID: Definitions but no namespace provided
      namespace = '';
      definitions = options[0];
    } else {
      throw new Error(`Space.messaging.define is missing definitions for ${BaseType}.`);
    }
    break;
  default:
    // VALID: Namespace and definitions provided
    namespace = options[0].toString();
    definitions = options[1];
    break;
  }

  _.each(definitions, (fields, className) => {
    let classPath = className;
    if (namespace !== '') classPath = `${namespace}.${className}`;
    let SubType = BaseType.extend(classPath);
    SubType.prototype.fields = () => _.extend(BaseType.prototype.fields(), fields);
    Space.resolvePath(namespace)[className] = SubType;
    subTypes[classPath] = SubType;
  });

  return subTypes;

};

Using those imports works because of global event definitions.

@DominikGuzei
Copy link
Copy Markdown
Member

@darko-mijic this is not how imports work. When you export default a object with sub properties, you cannot pick the sub-properties but only import the root object like this:

import domainEvents from '../../domain/events';

and then access them like this:

domainEvents.BankAccountOpened

or descructure them into the current scope like this:

{ BankAccountOpened, BankAccountCredited, BankAccountDebited } = domainEvents;

@darko-mijic
Copy link
Copy Markdown
Member Author

I know, that is why i mentioned this and that is how we where using command and event definitions before. ;) We will go back to using imported objects with command and event definitions as properties unless @rhyslbw has a better idea.

@rhyslbw
Copy link
Copy Markdown
Member

rhyslbw commented Jul 16, 2016

I like destructuring into the current scope for now for ease of refactoring at a later stage. I was just voicing the ideal that we should aim for when I made the earlier comment about importing named exports.

@DominikGuzei
Copy link
Copy Markdown
Member

@rhyslbw and @darko-mijic what is the current state of this PR? I don't like staying too long in single PRs which get bigger and bigger 😉

@rhyslbw rhyslbw closed this Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants