Giter VIP home page Giter VIP logo

datasource's Issues

Question about making changes to the inner datasource which is a MutableDataSource

There is a simple static tableview where it shows profile data. Since this data was not changing, it has used the StaticDataSource.

final class ProfileInfoCardViewModel {
    let dataSource: DataSource
    let profileViewModel: ProfileViewModel

    init(profileViewModel: ProfileViewModel) {
        self.profileViewModel = profileViewModel
        let user = profileViewModel.user.producer.skipNil()

        let proxyDataSource = ProxyDataSource()
        self.dataSource = proxyDataSource
        proxyDataSource.innerDataSource <~ user.map { user in
            if user.isLoggedInUser {
                if user.userLikes ?? 0 > 0 {
                    items.append(ProfileInfoRatingCellViewModel(userLikes : user.userLikes ?? 0))
                } else {
                    items.append(ProfileInfoNoRatingsYetCellViewModel())
                }
                items.append(ProfileInfoUpdateCellViewModel())
            }
            return StaticDataSource(items: items)
        }
    }
}

There is a new requirement to make this tableview dynamic. Upon a tap of a button, I need to insert/remove a cell from this tableview. So I opted to use the MutableDataSource. Also I changed the dataSource class variable from DataSource type to ProxyDataSource directly.

final class ProfileInfoCardViewModel {
    let dataSource: ProxyDataSource
    let profileViewModel: ProfileViewModel

    init(profileViewModel: ProfileViewModel) {
        self.profileViewModel = profileViewModel
        let user = profileViewModel.user.producer.skipNil()
        
        self.dataSource = ProxyDataSource()
        self.dataSource.innerDataSource <~ user.map { user in
            if user.isLoggedInUser {
                if user.userLikes ?? 0 > 0 {
                    items.append(ProfileInfoRatingCellViewModel(userLikes : user.userLikes ?? 0))
                } else {
                    items.append(ProfileInfoNoRatingsYetCellViewModel())
                }
                items.append(ProfileInfoUpdateCellViewModel())
            }
            return MutableDataSource(items)
        }
    }
    
    func userTappedToggleButton(_ show: Bool) {
        // do changes (insert/remove) to the inner mutable data source here

    }
}

The data loads fine still. However I'm having trouble figuring out how to make changes to the inner data source (add/remove an item).

Ambiguous reference to member 'map'

Hi,

In an old Swift 4 project which used this library, I had the following code.

let expanded = MutableProperty(false)
let dataSource = ProxyDataSource()

let s1 = StaticDataSource(items: [])
let s2 = StaticDataSource(items: [])

dataSource.innerDataSource <~ expanded.map { $0 ? s1 : s2 }

And it worked fine.

Recently I updated it to the latest version (1.0.1). Now I'm getting the following compile error.

Ambiguous reference to member 'map'

I checked the ReactiveSwift versions DataSource used in the old (3.0.1) and in the new version (6.0.1). The map function is still the same. So I'm not sure why error is occurring now.

Demo app

Memory leak and CPU overclocking

I am using Datasource for my collection view to populate data.. If the number of cells to be used are less than a said amount it works well, but if it is very large, say 30k. UI hangs and CPU overclocking is observed.

Code:

let optionsDataSource: MutableDataSource

self.optionsDataSource.replaceItems(with: Array(self.optionsCellModelForCurrentTask().prefix(100))) // Works well.. count is 100.

self.optionsDataSource.replaceItems(with: self.optionsCellModelForCurrentTask()) // CPU overclocking and memory leaks

self.optionsCellModelForCurrentTask() // count: 31000.

Screenshot 2019-09-18 at 12 57 35 PM

Any help would be highly appreciated.

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.