export function getAdjacencies(voucherBooks: List<EAPAVoucherBook>): List<VoucherBookAdjacency> {

    let prevIds = voucherBooks.insert(0, undefined);
    let nextIds = voucherBooks.push(undefined).skip(1);

    return voucherBooks.zipWith(
        (curr, prev, next) => getAdjacency(curr, prev, next),
        voucherBooks.insert(0, undefined),
        voucherBooks.push(undefined).skip(1)
    ).toList();
}
Example #2
0
function log(state: List<Message> = List<Message>(), action: Action): List<Message> {
    switch (action.type) {
        case ActionType.CHANGE_CHANNEL:
            // Clear log
            return List<Message>()
        case ActionType.LOG_LINE:
            return state.push(Object.freeze({id: -1, channel: -1, username: "******", content: action.payload.log, timestamp: new Date()}))
        case ActionType.CHAT_MESSAGE:
            return state.push(action.payload.message)
        default:
            return state
    }
}
Example #3
0
export function reduceOutputs(
  outputs: List<ImmutableOutput> = List(),
  output: OnDiskOutput
): List<ImmutableOutput> {
  // Find the last output to see if it's a stream type
  // If we don't find one, default to null
  const last = outputs.last(null);

  if (!last || !last.output_type) {
    return outputs.push(createImmutableOutput(output));
  }

  if (output.output_type !== "stream" || last.output_type !== "stream") {
    // If the last output type or the incoming output type isn't a stream
    // we just add it to the outputs
    // This is kind of like a "break" between streams if we get error,
    // display_data, execute_result, etc.
    return outputs.push(createImmutableOutput(output));
  }

  const streamOutput: OnDiskStreamOutput = output;

  if (typeof streamOutput.name === "undefined") {
    return outputs.push(createImmutableOutput(streamOutput));
  }

  function appendText(text: string): string {
    if (typeof streamOutput.text === "string") {
      return escapeCarriageReturnSafe(text + streamOutput.text);
    }
    return text;
  }

  // Invariant: size > 0, outputs.last() exists
  if (last.name === streamOutput.name) {
    return outputs.updateIn([outputs.size - 1, "text"], appendText);
  }

  // Check if there's a separate stream to merge with
  const nextToLast = outputs.butLast().last(null);

  if (
    nextToLast &&
    nextToLast.output_type === "stream" &&
    nextToLast.name === streamOutput.name
  ) {
    return outputs.updateIn([outputs.size - 2, "text"], appendText);
  }
  // If nothing else matched, just append it
  return outputs.push(createImmutableOutput(streamOutput));
}
Example #4
0
    addNode(node: any) {
        var nodes = this.nodes.push(node);
        var children = this.children.set(node.id, List<any>());
        var parents = this.parents.set(node.id, List<any>());

        return new Graph(nodes, children, parents);
    }
Example #5
0
export function reducer(state: List<SettingItem> = List<SettingItem>(), action: ITodoAction) {

  function indexOf(uuid: string) {
    return state.findIndex((i: SettingItem) => i.uuid === action.itemId);
  }

  function createItemObj(text: string) {
    if (!text) {
      return new SettingItem();
    }
    if (text.indexOf('|') >= 0) {
      // parse the text for name|value format
      let tokens = text.split('|');
      if (tokens.length > 1) {
        return new SettingItem({name: tokens[0], value: tokens[1], completed: false, uuid: uuid.v4()});
      }
    }
    return new SettingItem({name: '[no name]', value: text, completed: false, uuid: uuid.v4()});
  }

  switch (action.type) {
    case 'ADD':
      return state.push(createItemObj(action.text));
    case 'REMOVE':
      return List<SettingItem>(state.filter((i: SettingItem) => i.uuid !== action.itemId));
    case 'UPDATE_ITEM_VALUE':
      return state.update(indexOf(action.itemId), (i: SettingItem) => i.setValue(action.text));
    case 'UPDATE_ITEM_COMPLETION':
      return state.update(indexOf(action.itemId), (i: SettingItem) => i.setCompleted(action.completed));
    default:
      return state;
  }

}
Example #6
0
function deleteObjectIdRecur(obj: any, stack: List<object>) {
  for (let i=0; i< stack.size; i++) {
    if (i > 10) {
      logger.warn("deleteObjectIdRecur: Too deep stack");
      logger.warn(obj);
      return;
    }
    if (obj === stack[i]) {
      logger.warn("deleteObjectIdRecur: recurrence found");
      logger.warn(obj);
      return;
    }
  }
  if (obj !== null && typeof(obj) == 'object') {
    if (obj instanceof Promise) {
      logger.warn("deleteObjectIdRecur: Object is promise");
    } else if (Array.isArray(obj)) {
      for (let i = 0; i < obj.length; i++) {
        if (obj[i] && obj[i]._id) deleteObjectIdRecur(obj[i], stack.push(obj));  //recursive del calls on array elements
      }
    } else {
      delete obj._id;
      Object.keys(obj).forEach(function(key) {
        if (obj[key] && obj[key]._id) deleteObjectIdRecur(obj[key], stack.push(obj)); //recursive del calls on object elements
      });
    }
  }
}
Example #7
0
export default function(state: List<TaskModel>, action: ITaskAction) {

  function indexOf(id: string): number {
    return state.findIndex((i: TaskModel) => i.id === id);
  }

  switch (action.type) {
    case LOAD_TASKS:
      state = action.taskList;
      return List<TaskModel>(state);
    case UPDATE_TASK:
      let index = state.findIndex((task) => task.id === action.task.id);
      return state.set(
        index,
        new TaskModel({
          id: action.task.id,
          title: action.task.title,
          details: action.task.details,
          dueDate: action.task.dueDate,
          completed: action.task.completed,
          completedDate: action.task.completedDate
        })
      );
    case COMPLETE_TASK:
      let completedTaskIndex = state.findIndex((task) => task.id === action.id);
      return state.delete(completedTaskIndex);
    case ADD_TASK:
      return state.push(action.task);
    default:
      return List<TaskModel>(state);
  }
}
Example #8
0
	public addTodo(title: string){
        this.history = this.history.push(this.todos);
		this.todos.push(fromJS({
			id: Utils.uuid(),
			title: title,
			completed: false
		}));
	}
Example #9
0
 .subscribe(results => {
     if (results.type === ItemNameDialogResultType.Saved) {
         let epic = new Epic(this.modelId, this.router, this._createStoryDialog, results.name);
         epic.observeEvents();
         this._epics = this._epics.push(epic);
     }
     this._createEpicDialog.close();
 });
Example #10
0
export function adnet(state: Map<string,any> = Map<string,any>(), action: any): Map<string,any> {

    var indexOfRateId = function (i_rateId: string) {
        return rates.findIndex((i: AdnetRateModel) => i.rateId() === i_rateId);
    }
    var indexOfCustomerId = function (i_adnetCustomerId: string) {
        return customers.findIndex((i: AdnetCustomerModel) => i.customerId() === i_adnetCustomerId);
    }
    switch (action.type) {
        case AdnetActions.RECEIVE_CUSTOMERS: {
            return state.setIn(['customers'], action.customers);
        }
        case AdnetActions.RECEIVE_RATES: {
            return state.setIn(['rates'], action.rates);
        }
        case AdnetActions.UPDATE_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);

            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                return rate.setField('rateMap', action.payload.rateTable)
            });
            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                rate = rate.setField('hourRate0', action.payload.adHourlyRate["0"])
                rate = rate.setField('hourRate1', action.payload.adHourlyRate["1"])
                rate = rate.setField('hourRate2', action.payload.adHourlyRate["2"])
                rate = rate.setField('hourRate3', action.payload.adHourlyRate["3"])
                return rate;
            });
            return state.setIn(['rates'], rates);
        }
        case AdnetActions.ADD_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            rates = rates.push(action.adnetRateModel);
            return state.setIn(['rates'], rates);
        }
        case AdnetActions.REMOVE_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            var updatedRates:List<AdnetRateModel> = rates.filter((adnetRateModel:AdnetRateModel) => adnetRateModel.rateId() !== action.rateId) as List<AdnetRateModel>;
            return state.setIn(['rates'], updatedRates);
        }
        case AdnetActions.UPDATE_ADNET_CUSTOMER: {
            var customers: List<AdnetCustomerModel> = state.getIn(['customers'])
            customers = customers.update(indexOfCustomerId(action.payload.Key), (customer: AdnetCustomerModel) => {
                return customer.setData<AdnetCustomerModel>(AdnetCustomerModel, action.payload)
            });
            return state.setIn(['customers'], customers);
        }
        case AdnetActions.RENAME_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                return rate.setField('label', action.payload.newLabel)
            });
            return state.setIn(['rates'], rates);
        }
        default:
            return state;
    }
}