Code Monkey home page Code Monkey logo

aspen-core's People

Contributors

logandark avatar zikaari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

chillicream

aspen-core's Issues

Use `subarray` instead of `slice` for twice as fast splicing

Benchmarks show subarraying is twice as fast than slicing, because slicing "copies", but subarraying "references" the value(s).

https://github.com/NeekSandhu/aspen-core/blob/6ba61c8e3b81d296417b41fd1b306e7c09983f6e/src/Directory.ts#L19-L27

Before this change can be patched into master, we need an automated benchmarking suite along with unit testing to ensure we don't break things and at the same time don't slow down exisiting implementation.

Example for iterateTopDown?

Hi! I'm trying to write a function that iterates through the whole tree to find all items that a decoration applies to (incl. cascading targets targeted by SelfAndChildren and not negated).

I tried something like this:

function getActiveFilesCascade(model: FileTreeModel) {
  const activeFiles: FileOrDir[] = [];
  model.root.iterateTopDown((item, next, stepIn, stepOut) => {
    if (!item) return stepOut();
    const decorations = model.decorations.getDecorations(item);
    if (decorations.classlist.indexOf('active') !== -1) {
      activeFiles.push(item);
    }
    if (item.type === FileType.Directory) {
      return stepIn();
    }
    next();
  });
  return activeFiles;
}

given a tree like this

root
- A
- B
  - C
  - D
- E

This iterates [A, B, C, D, null, null]. It never gets to E.

The problem seems to be that it doesn't return to the previous iterator after stepOut. I wonder if this might be an implementation bug in iterateTopDown? If I understand correctly, stepIn puts the next iterator on the stack, and stepOut pops that same iterator, while not allowing to pop the first level. So how can we resume the top level iterator?

Or maybe there is another easier or more performant way to achieve this (find all items a decoration applies to)?

Multiple roots and items that are not files

Multiple "roots" and special items (like "buttons" at the bottom, or section separators, or an item at the top of the list describing the root directory, etc.) can be added by essentially making a virtual filesystem using the IBasicFileSystemHost. However, this is a lot of effort and it would be nice to know other solutions to the problem.

Does anything like this currently exist? If not, do you have plans to add any?

Edit: By "multiple roots", I mean displaying items as siblings in the model when they aren't actually siblings on the real filesystem (for example, displaying /home/logandark/folder1 and /etc/whatever). AFAIK, since aspen only represents items as having a filename and not a path, this is currently impossible just by adding items to the model, even if those items are artificially injected. But feel free to correct me if I'm wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.